mirror of
https://github.com/filegator/filegator.git
synced 2025-08-13 08:24:22 +02:00
refactoring
This commit is contained in:
@@ -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,14 +79,16 @@ class Tmpfs implements Service, TmpfsInterface
|
||||
public function findAll($pattern): array
|
||||
{
|
||||
$files = [];
|
||||
|
||||
foreach (glob($this->getPath().$pattern) as $filename) {
|
||||
if (is_file($filename)) {
|
||||
$files[] = [
|
||||
'name' => basename($filename),
|
||||
'size' => filesize($filename),
|
||||
'time' => filemtime($filename),
|
||||
];
|
||||
$matches = glob($this->getPath().$pattern);
|
||||
if (! empty($matches)) {
|
||||
foreach ($matches as $filename) {
|
||||
if (is_file($filename)) {
|
||||
$files[] = [
|
||||
'name' => basename($filename),
|
||||
'size' => filesize($filename),
|
||||
'time' => filemtime($filename),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user