mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-20 12:51:30 +02:00
A little clean up
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Controllers;
|
||||
use App\CallbackStream;
|
||||
use App\Config;
|
||||
use App\Support\Str;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RuntimeException;
|
||||
@@ -52,16 +53,17 @@ class ZipController
|
||||
$zip = $this->createZip($path, $files);
|
||||
$size = $zip->finish();
|
||||
|
||||
$response = $this
|
||||
->augmentHeadersWithEstimatedSize($response, $size)
|
||||
->withBody(new CallbackStream(function () use ($zip) {
|
||||
$response = $this->augmentHeadersWithEstimatedSize($response, $size)->withBody(
|
||||
new CallbackStream(function () use ($zip) {
|
||||
$zip->executeSimulation();
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** Create a zip stream from a directory.
|
||||
/**
|
||||
* Create a zip stream from a directory.
|
||||
*
|
||||
* @throws \ZipStream\Exception\FileNotFoundException
|
||||
* @throws \ZipStream\Exception\FileNotReadableException
|
||||
@@ -77,16 +79,12 @@ class ZipController
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$modifiedTime = null;
|
||||
|
||||
try {
|
||||
$modifiedTime = new \DateTime('@' . (int) $file->getMTime());
|
||||
} catch (RuntimeException $e) {
|
||||
$lstat_data = lstat($file->getPathname());
|
||||
if ($lstat_data) {
|
||||
$modifiedTime = new \DateTime('@' . (int) ['mtime']);
|
||||
}
|
||||
$modifiedTime = new DateTime('@' . (int) $file->getMTime());
|
||||
} catch (RuntimeException) {
|
||||
$modifiedTime = new DateTime('@' . (int) lstat($file->getPathname())['mtime']);
|
||||
}
|
||||
|
||||
$zip->addFileFromPath(
|
||||
$this->stripPath($file, $path),
|
||||
(string) $file->getRealPath(),
|
||||
@@ -109,11 +107,7 @@ class ZipController
|
||||
/** Return the path to a file with the preceding root path stripped. */
|
||||
protected function stripPath(SplFileInfo $file, string $path): string
|
||||
{
|
||||
$pattern = sprintf(
|
||||
'/^%s%s?/',
|
||||
preg_quote($path, '/'),
|
||||
preg_quote(DIRECTORY_SEPARATOR, '/')
|
||||
);
|
||||
$pattern = sprintf('/^%s%s?/', preg_quote($path, '/'), preg_quote(DIRECTORY_SEPARATOR, '/'));
|
||||
|
||||
return (string) preg_replace($pattern, '', $file->getPathname());
|
||||
}
|
||||
|
@@ -30,6 +30,11 @@ parameters:
|
||||
count: 2
|
||||
path: app/src/Controllers/SearchController.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'mtime' on array\\{0\\: int, 1\\: int, 2\\: int, 3\\: int, 4\\: int, 5\\: int, 6\\: int, 7\\: int, \\.\\.\\.\\}\\|false\\.$#"
|
||||
count: 1
|
||||
path: app/src/Controllers/ZipController.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Controllers\\\\ZipController\\:\\:generateFileName\\(\\) should return string but returns string\\|null\\.$#"
|
||||
count: 1
|
||||
@@ -95,11 +100,6 @@ parameters:
|
||||
count: 1
|
||||
path: app/src/ViewFunctions/SizeForHumans.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$finfo of function finfo_buffer expects finfo, finfo\\|false given\\.$#"
|
||||
count: 1
|
||||
path: tests/Controllers/ZipControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$finfo of function finfo_buffer expects finfo, finfo\\|false given\\.$#"
|
||||
count: 1
|
||||
|
Reference in New Issue
Block a user