mirror of
https://github.com/filegator/filegator.git
synced 2025-07-31 22:40:14 +02:00
refactoring
This commit is contained in:
@@ -33,7 +33,7 @@ class App
|
||||
$container->get($key)->init(isset($service['config']) ? $service['config'] : []);
|
||||
}
|
||||
|
||||
$response->send($request);
|
||||
$response->send();
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ class DownloadController
|
||||
public function download($path_encoded, Request $request, Response $response, StreamedResponse $streamedResponse)
|
||||
{
|
||||
try {
|
||||
$file = $this->storage->readStream(base64_decode($path_encoded));
|
||||
$file = $this->storage->readStream((string) base64_decode($path_encoded));
|
||||
} catch (\Exception $e) {
|
||||
return $response->redirect('/');
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class DownloadController
|
||||
|
||||
public function batchDownloadStart(Request $request, StreamedResponse $streamedResponse, TmpfsInterface $tmpfs)
|
||||
{
|
||||
$uniqid = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('uniqid'));
|
||||
$uniqid = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('uniqid'));
|
||||
|
||||
$streamedResponse->setCallback(function () use ($tmpfs, $uniqid) {
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@@ -42,7 +42,7 @@ class UploadController
|
||||
public function chunkCheck(Request $request, Response $response)
|
||||
{
|
||||
$file_name = $request->input('resumableFilename', 'file');
|
||||
$identifier = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('resumableIdentifier'));
|
||||
$identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier'));
|
||||
$chunk_number = (int) $request->input('resumableChunkNumber');
|
||||
|
||||
$chunk_file = 'multipart_'.$identifier.$file_name.'.part'.$chunk_number;
|
||||
@@ -61,7 +61,7 @@ class UploadController
|
||||
$chunk_number = (int) $request->input('resumableChunkNumber');
|
||||
$total_chunks = (int) $request->input('resumableTotalChunks');
|
||||
$total_size = (int) $request->input('resumableTotalSize');
|
||||
$identifier = preg_replace('/[^0-9a-zA-Z_]/', '', $request->input('resumableIdentifier'));
|
||||
$identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier'));
|
||||
|
||||
$file = $request->files->get('file');
|
||||
|
||||
|
@@ -21,7 +21,7 @@ class Request extends SymfonyRequest
|
||||
|
||||
// then look into JSON content, fallback to default
|
||||
if ($value === null) {
|
||||
$content = json_decode($this->getContent());
|
||||
$content = json_decode((string) $this->getContent());
|
||||
$value = isset($content->{$key}) ? $content->{$key} : $default;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Request extends SymfonyRequest
|
||||
$params = [];
|
||||
|
||||
// first look into JSON content
|
||||
$content = json_decode($this->getContent());
|
||||
$content = json_decode((string) $this->getContent());
|
||||
if (! empty($content)) {
|
||||
foreach ($content as $key => $param) {
|
||||
$params[$key] = $param;
|
||||
|
@@ -96,7 +96,7 @@ class ZipArchiver implements Service, ArchiverInterface
|
||||
foreach ($contents as $item) {
|
||||
$stream = $archive->readStream($item['path']);
|
||||
if ($item['type'] == 'dir') {
|
||||
$storage->createDir($destination, $item['path'], $stream);
|
||||
$storage->createDir($destination, $item['path']);
|
||||
}
|
||||
if ($item['type'] == 'file') {
|
||||
$storage->store($destination.'/'.$item['dirname'], $item['basename'], $stream);
|
||||
|
@@ -29,6 +29,8 @@ class Database implements Service, AuthInterface
|
||||
|
||||
protected $session;
|
||||
|
||||
protected $conn;
|
||||
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
@@ -174,11 +176,11 @@ class Database implements Service, AuthInterface
|
||||
{
|
||||
$new = new User();
|
||||
|
||||
$new->setRole($user->role);
|
||||
$new->setHomedir($user->homedir);
|
||||
$new->setPermissions($user->permissions, true);
|
||||
$new->setUsername($user->username);
|
||||
$new->setName($user->name);
|
||||
$new->setRole(isset($user->role) ? $user->role : 'guest');
|
||||
$new->setHomedir(isset($user->homedir) ? $user->homedir : '/');
|
||||
$new->setPermissions(isset($user->permissions) ? $user->permissions : '', true);
|
||||
$new->setUsername(isset($user->username) ? $user->username : '');
|
||||
$new->setName(isset($user->name) ? $user->name : 'Guest');
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
@@ -189,7 +189,7 @@ class JsonFile implements Service, AuthInterface
|
||||
|
||||
protected function getUsers(): array
|
||||
{
|
||||
$users = json_decode(file_get_contents($this->file), true);
|
||||
$users = json_decode((string) file_get_contents($this->file), true);
|
||||
|
||||
return is_array($users) ? $users : [];
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ class MonoLogger implements Service, LoggerInterface
|
||||
$handler->registerFatalHandler();
|
||||
}
|
||||
|
||||
public function log(string $message, string $level = Logger::INFO)
|
||||
public function log(string $message, int $level = Logger::INFO)
|
||||
{
|
||||
$this->logger->log($level, $message);
|
||||
}
|
||||
|
@@ -12,5 +12,5 @@ namespace Filegator\Services\Logger;
|
||||
|
||||
interface LoggerInterface
|
||||
{
|
||||
public function log(string $message, string $level);
|
||||
public function log(string $message, int $level);
|
||||
}
|
||||
|
@@ -33,6 +33,8 @@ class Router implements Service
|
||||
|
||||
protected $container;
|
||||
|
||||
protected $user;
|
||||
|
||||
public function __construct(Request $request, AuthInterface $auth, Container $container)
|
||||
{
|
||||
$this->request = $request;
|
||||
|
@@ -40,22 +40,22 @@ class SessionStorage implements Service, SessionStorageInterface
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->getSession()->save();
|
||||
return $this->getSession() !== null ? $this->getSession()->save() : false;
|
||||
}
|
||||
|
||||
public function set(string $key, $data)
|
||||
{
|
||||
return $this->getSession()->set($key, $data);
|
||||
return $this->getSession() !== null ? $this->getSession()->set($key, $data) : false;
|
||||
}
|
||||
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
return $this->getSession() ? $this->getSession()->get($key, $default) : $default;
|
||||
return $this->getSession() !== null ? $this->getSession()->get($key, $default) : $default;
|
||||
}
|
||||
|
||||
public function invalidate()
|
||||
{
|
||||
if (! $this->getSession()->isStarted()) {
|
||||
if ($this->getSession() !== null || ! $this->getSession()->isStarted()) {
|
||||
$this->getSession()->start();
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,7 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
{
|
||||
$filename = $this->sanitizeFilename($filename);
|
||||
|
||||
return file_get_contents($this->getPath().$filename);
|
||||
return (string) file_get_contents($this->getPath().$filename);
|
||||
}
|
||||
|
||||
public function readStream(string $filename): array
|
||||
@@ -79,8 +79,9 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
public function findAll($pattern): array
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach (glob($this->getPath().$pattern) as $filename) {
|
||||
$matches = glob($this->getPath().$pattern);
|
||||
if (! empty($matches)) {
|
||||
foreach ($matches as $filename) {
|
||||
if (is_file($filename)) {
|
||||
$files[] = [
|
||||
'name' => basename($filename),
|
||||
@@ -89,6 +90,7 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
@@ -117,7 +119,7 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
|
||||
private function sanitizeFilename($filename)
|
||||
{
|
||||
$filename = preg_replace(
|
||||
$filename = (string) preg_replace(
|
||||
'~
|
||||
[<>:"/\\|?*]| # file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
[\x00-\x1F]| # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
||||
@@ -125,12 +127,19 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
[;\\\{}^\~`] # other non-safe
|
||||
~x',
|
||||
'-',
|
||||
$filename
|
||||
(string) $filename
|
||||
);
|
||||
|
||||
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
return mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)).($ext ? '.'.$ext : '');
|
||||
return mb_strcut(
|
||||
pathinfo($filename, PATHINFO_FILENAME),
|
||||
0,
|
||||
255 - ($ext ? strlen($ext) + 1 : 0),
|
||||
(string) mb_detect_encoding($filename)
|
||||
).(
|
||||
$ext ? '.'.$ext : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5",
|
||||
"symfony/var-dumper": "^4.2",
|
||||
"league/flysystem-memory": "^1.0"
|
||||
"league/flysystem-memory": "^1.0",
|
||||
"phpstan/phpstan": "^0.11.8"
|
||||
}
|
||||
}
|
||||
|
973
composer.lock
generated
973
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user