instances added god may help
This commit is contained in:
@@ -12,7 +12,7 @@ class ImportTempFileService
|
||||
* @param array<string, mixed> $upload
|
||||
* @return array{ok:bool, path?:string, code?:string}
|
||||
*/
|
||||
public static function storeUploadedFile(array $upload): array
|
||||
public function storeUploadedFile(array $upload): array
|
||||
{
|
||||
$tmpName = (string) ($upload['tmp_name'] ?? '');
|
||||
$name = (string) ($upload['name'] ?? '');
|
||||
@@ -31,16 +31,16 @@ class ImportTempFileService
|
||||
if ($size > self::MAX_UPLOAD_BYTES) {
|
||||
return ['ok' => false, 'code' => 'upload_too_large'];
|
||||
}
|
||||
if (!self::isAllowedExtension($name)) {
|
||||
if (!$this->isAllowedExtension($name)) {
|
||||
return ['ok' => false, 'code' => 'invalid_file_type'];
|
||||
}
|
||||
|
||||
$dir = self::tmpDir();
|
||||
$dir = $this->tmpDir();
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0775, true) && !is_dir($dir)) {
|
||||
return ['ok' => false, 'code' => 'unexpected_error'];
|
||||
}
|
||||
|
||||
self::cleanupExpired();
|
||||
$this->cleanupExpired();
|
||||
|
||||
try {
|
||||
$target = $dir . '/import_' . bin2hex(random_bytes(16)) . '.csv';
|
||||
@@ -65,13 +65,13 @@ class ImportTempFileService
|
||||
return ['ok' => true, 'path' => $target];
|
||||
}
|
||||
|
||||
public static function delete(string $path): void
|
||||
public function delete(string $path): void
|
||||
{
|
||||
$path = trim($path);
|
||||
if ($path === '') {
|
||||
return;
|
||||
}
|
||||
if (!self::isInTmpDir($path)) {
|
||||
if (!$this->isInTmpDir($path)) {
|
||||
return;
|
||||
}
|
||||
if (is_file($path)) {
|
||||
@@ -79,9 +79,9 @@ class ImportTempFileService
|
||||
}
|
||||
}
|
||||
|
||||
public static function cleanupExpired(): void
|
||||
public function cleanupExpired(): void
|
||||
{
|
||||
$dir = self::tmpDir();
|
||||
$dir = $this->tmpDir();
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class ImportTempFileService
|
||||
}
|
||||
}
|
||||
|
||||
public static function storageBase(): string
|
||||
public function storageBase(): string
|
||||
{
|
||||
if (defined('APP_STORAGE_PATH') && APP_STORAGE_PATH) {
|
||||
return rtrim((string) APP_STORAGE_PATH, '/');
|
||||
@@ -111,20 +111,20 @@ class ImportTempFileService
|
||||
return rtrim(dirname(__DIR__, 3) . '/storage', '/');
|
||||
}
|
||||
|
||||
public static function tmpDir(): string
|
||||
public function tmpDir(): string
|
||||
{
|
||||
return self::storageBase() . self::TMP_SUBDIR;
|
||||
return $this->storageBase() . self::TMP_SUBDIR;
|
||||
}
|
||||
|
||||
private static function isAllowedExtension(string $name): bool
|
||||
private function isAllowedExtension(string $name): bool
|
||||
{
|
||||
$extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
|
||||
return in_array($extension, ['csv', 'txt'], true);
|
||||
}
|
||||
|
||||
private static function isInTmpDir(string $path): bool
|
||||
private function isInTmpDir(string $path): bool
|
||||
{
|
||||
$tmpDir = self::tmpDir();
|
||||
$tmpDir = $this->tmpDir();
|
||||
$realTmpDir = realpath($tmpDir);
|
||||
$realPath = realpath($path);
|
||||
if ($realTmpDir === false || $realPath === false) {
|
||||
|
||||
Reference in New Issue
Block a user