Compare commits
3
Commits
v1.13
..
614f21b240
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
614f21b240 | ||
|
|
1bca442f55 | ||
|
|
aac6d5b80a |
+39
-4
@@ -38,7 +38,7 @@ class File
|
|||||||
4 => 'No file was uploaded.',
|
4 => 'No file was uploaded.',
|
||||||
6 => 'Missing a temporary folder.',
|
6 => 'Missing a temporary folder.',
|
||||||
7 => 'Failed to write file to disk.',
|
7 => 'Failed to write file to disk.',
|
||||||
8 => 'A PHP extension stopped the file upload.'
|
8 => 'A PHP extension stopped the file upload.',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,14 +65,19 @@ class File
|
|||||||
*/
|
*/
|
||||||
public function rename(): string
|
public function rename(): string
|
||||||
{
|
{
|
||||||
if (!empty($this->newName)) return $this->newName;
|
if (!empty($this->newName))
|
||||||
|
return $this->newName;
|
||||||
if (!file_exists($this->getTmpPath())) {
|
if (!file_exists($this->getTmpPath())) {
|
||||||
throw new Exception('(' . $this->name . ')Failed to open stream: No such file or directory');
|
throw new Exception('(' . $this->name . ')Failed to open stream: No such file or directory');
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash = md5_file($this->getTmpPath());
|
$hash = md5_file($this->getTmpPath());
|
||||||
|
$later = match ($this->type) {
|
||||||
$later = '.' . exif_imagetype($this->getTmpPath());
|
'image/jpeg', 'image/jpg' => '.jpeg',
|
||||||
|
'image/gif' => '.gif',
|
||||||
|
'image/png' => '.png',
|
||||||
|
default => '.' . $this->exif_imageType(),
|
||||||
|
};
|
||||||
|
|
||||||
$match = '/(\w{12})(\w{5})(\w{9})(\w{6})/';
|
$match = '/(\w{12})(\w{5})(\w{9})(\w{6})/';
|
||||||
$tmp = preg_replace($match, '$1-$2-$3-$4', $hash);
|
$tmp = preg_replace($match, '$1-$2-$3-$4', $hash);
|
||||||
@@ -80,6 +85,36 @@ class File
|
|||||||
return $this->name = strtoupper($tmp) . $later;
|
return $this->name = strtoupper($tmp) . $later;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int|null
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function exif_imageType(): ?int
|
||||||
|
{
|
||||||
|
return match (\exif_imagetype($this->tmp_name)) {
|
||||||
|
IMAGETYPE_GIF => '.gif',
|
||||||
|
IMAGETYPE_JPEG => '.jpg',
|
||||||
|
IMAGETYPE_PNG => '.png',
|
||||||
|
IMAGETYPE_SWF => '.swf',
|
||||||
|
IMAGETYPE_PSD => '.psd',
|
||||||
|
IMAGETYPE_BMP => '.bmp',
|
||||||
|
IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM => '.tiff',
|
||||||
|
IMAGETYPE_JPC => '.jpc',
|
||||||
|
IMAGETYPE_JP2 => '.jp2',
|
||||||
|
IMAGETYPE_JPX => '.jpx',
|
||||||
|
IMAGETYPE_JB2 => '.jb2',
|
||||||
|
IMAGETYPE_SWC => '.swc',
|
||||||
|
IMAGETYPE_IFF => '.iff',
|
||||||
|
IMAGETYPE_WBMP => '.wbmp',
|
||||||
|
IMAGETYPE_XBM => '.xbm',
|
||||||
|
IMAGETYPE_ICO => '.ico',
|
||||||
|
IMAGETYPE_WEBP => '.webp',
|
||||||
|
IMAGETYPE_AVIF => '.avif',
|
||||||
|
default => throw new Exception('未知的图片类型'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
+15
-8
@@ -239,8 +239,8 @@ class Router
|
|||||||
);
|
);
|
||||||
$scanner->setConfig($scanConfig);
|
$scanner->setConfig($scanConfig);
|
||||||
|
|
||||||
$normalizedAppPath = str_replace('\\', '/', APP_PATH . 'app');
|
$normalizedAppPath = str_replace('\\', '/', realpath(APP_PATH . 'app') ?: APP_PATH . 'app');
|
||||||
$normalizedRoutePath = str_replace('\\', '/', APP_PATH . 'routes');
|
$normalizedRoutePath = str_replace('\\', '/', realpath(APP_PATH . 'routes') ?: APP_PATH . 'routes');
|
||||||
$routeChanged = false;
|
$routeChanged = false;
|
||||||
$appChangedFiles = [];
|
$appChangedFiles = [];
|
||||||
|
|
||||||
@@ -255,8 +255,12 @@ class Router
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($appChangedFiles)) {
|
||||||
|
$appChangedFiles = $scanner->expandDependentFiles($appChangedFiles, APP_PATH . 'app/');
|
||||||
|
}
|
||||||
|
|
||||||
$usedArtifact = false;
|
$usedArtifact = false;
|
||||||
if (($scanConfig['cache_enabled'] ?? false) && !$routeChanged && $artifactState->has(static::$type)) {
|
if (($scanConfig['cache_enabled'] ?? false) && $artifactState->has(static::$type)) {
|
||||||
$artifact = $artifactState->load(static::$type);
|
$artifact = $artifactState->load(static::$type);
|
||||||
$router = $container->get(DataGrip::class)->get(static::$type);
|
$router = $container->get(DataGrip::class)->get(static::$type);
|
||||||
$usedArtifact = $router->importArtifact($artifact, $appChangedFiles);
|
$usedArtifact = $router->importArtifact($artifact, $appChangedFiles);
|
||||||
@@ -266,8 +270,8 @@ class Router
|
|||||||
// route artifact 只加速注解路由,不能替代 routes/*.php 的注册副作用。
|
// route artifact 只加速注解路由,不能替代 routes/*.php 的注册副作用。
|
||||||
$this->read_dir_file(APP_PATH . 'routes');
|
$this->read_dir_file(APP_PATH . 'routes');
|
||||||
|
|
||||||
if (!$routeChanged && !empty($appChangedFiles) && ($scanConfig['cache_enabled'] ?? false)) {
|
if (!empty($appChangedFiles) && ($scanConfig['cache_enabled'] ?? false)) {
|
||||||
$scanner->scanFiles($appChangedFiles, APP_PATH . 'app/', null, !$usedArtifact);
|
$scanner->scanFiles($appChangedFiles, APP_PATH . 'app/', null, true);
|
||||||
} elseif (!$usedArtifact) {
|
} elseif (!$usedArtifact) {
|
||||||
$scanner->scan(APP_PATH . 'app/');
|
$scanner->scan(APP_PATH . 'app/');
|
||||||
} else {
|
} else {
|
||||||
@@ -462,8 +466,12 @@ class Router
|
|||||||
private function resolve_file($files): void
|
private function resolve_file($files): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
static::$currentSourceFile = str_replace('\\', '/', realpath($files) ?: $files);
|
$file = realpath($files) ?: $files;
|
||||||
include "$files";
|
static::$currentSourceFile = str_replace('\\\\', '/', $file);
|
||||||
|
if (function_exists('opcache_invalidate')) {
|
||||||
|
@opcache_invalidate($file, true);
|
||||||
|
}
|
||||||
|
include $file;
|
||||||
} catch (\Throwable $throwable) {
|
} catch (\Throwable $throwable) {
|
||||||
\Kiri::getLogger()->json_log($throwable);
|
\Kiri::getLogger()->json_log($throwable);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -471,7 +479,6 @@ class Router
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getCurrentSourceFile(): ?string
|
public static function getCurrentSourceFile(): ?string
|
||||||
{
|
{
|
||||||
return static::$currentSourceFile;
|
return static::$currentSourceFile;
|
||||||
|
|||||||
Reference in New Issue
Block a user