mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-02 13:09:53 +09:00
Update to laravel 7
This commit is contained in:
@@ -34,7 +34,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
*/
|
||||
public function __construct(string $dsn)
|
||||
{
|
||||
if (0 !== strpos($dsn, 'file:')) {
|
||||
if (!str_starts_with($dsn, 'file:')) {
|
||||
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $dsn));
|
||||
}
|
||||
$this->folder = substr($dsn, 5);
|
||||
@@ -47,7 +47,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null)
|
||||
public function find(?string $ip, ?string $url, ?int $limit, ?string $method, int $start = null, int $end = null, string $statusCode = null): array
|
||||
{
|
||||
$file = $this->getIndexFilename();
|
||||
|
||||
@@ -56,15 +56,15 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
}
|
||||
|
||||
$file = fopen($file, 'r');
|
||||
fseek($file, 0, SEEK_END);
|
||||
fseek($file, 0, \SEEK_END);
|
||||
|
||||
$result = [];
|
||||
while (\count($result) < $limit && $line = $this->readLineFromFile($file)) {
|
||||
$values = str_getcsv($line);
|
||||
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values;
|
||||
[$csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode] = $values;
|
||||
$csvTime = (int) $csvTime;
|
||||
|
||||
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) {
|
||||
if ($ip && !str_contains($csvIp, $ip) || $url && !str_contains($csvUrl, $url) || $method && !str_contains($csvMethod, $method) || $statusCode && !str_contains($csvStatusCode, $statusCode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -113,13 +113,21 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($token)
|
||||
public function read(string $token): ?Profile
|
||||
{
|
||||
if (!$token || !file_exists($file = $this->getFilename($token))) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
|
||||
if (\function_exists('gzcompress')) {
|
||||
$file = 'compress.zlib://'.$file;
|
||||
}
|
||||
|
||||
if (!$data = unserialize(file_get_contents($file))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createProfileFromData($token, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +135,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function write(Profile $profile)
|
||||
public function write(Profile $profile): bool
|
||||
{
|
||||
$file = $this->getFilename($profile->getToken());
|
||||
|
||||
@@ -161,7 +169,14 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
'status_code' => $profile->getStatusCode(),
|
||||
];
|
||||
|
||||
if (false === file_put_contents($file, serialize($data))) {
|
||||
$context = stream_context_create();
|
||||
|
||||
if (\function_exists('gzcompress')) {
|
||||
$file = 'compress.zlib://'.$file;
|
||||
stream_context_set_option($context, 'zlib', 'level', 3);
|
||||
}
|
||||
|
||||
if (false === file_put_contents($file, serialize($data), 0, $context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -189,11 +204,9 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* Gets filename to store data, associated to the token.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return string The profile filename
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilename($token)
|
||||
protected function getFilename(string $token)
|
||||
{
|
||||
// Uses 4 last characters, because first are mostly the same.
|
||||
$folderA = substr($token, -2, 2);
|
||||
@@ -205,7 +218,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
/**
|
||||
* Gets the index filename.
|
||||
*
|
||||
* @return string The index filename
|
||||
* @return string
|
||||
*/
|
||||
protected function getIndexFilename()
|
||||
{
|
||||
@@ -219,7 +232,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
*
|
||||
* @param resource $file The file resource, with the pointer placed at the end of the line to read
|
||||
*
|
||||
* @return mixed A string representing the line or null if beginning of file is reached
|
||||
* @return mixed
|
||||
*/
|
||||
protected function readLineFromFile($file)
|
||||
{
|
||||
@@ -227,7 +240,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
$position = ftell($file);
|
||||
|
||||
if (0 === $position) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
@@ -249,7 +262,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
|
||||
$position += $upTo;
|
||||
$line = substr($buffer, $upTo + 1).$line;
|
||||
fseek($file, max(0, $position), SEEK_SET);
|
||||
fseek($file, max(0, $position), \SEEK_SET);
|
||||
|
||||
if ('' !== $line) {
|
||||
break;
|
||||
@@ -259,7 +272,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
return '' === $line ? null : $line;
|
||||
}
|
||||
|
||||
protected function createProfileFromData($token, $data, $parent = null)
|
||||
protected function createProfileFromData(string $token, array $data, Profile $parent = null)
|
||||
{
|
||||
$profile = new Profile($token);
|
||||
$profile->setIp($data['ip']);
|
||||
@@ -282,7 +295,15 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
$profile->addChild($this->createProfileFromData($token, unserialize(file_get_contents($file)), $profile));
|
||||
if (\function_exists('gzcompress')) {
|
||||
$file = 'compress.zlib://'.$file;
|
||||
}
|
||||
|
||||
if (!$childData = unserialize(file_get_contents($file))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$profile->addChild($this->createProfileFromData($token, $childData, $profile));
|
||||
}
|
||||
|
||||
return $profile;
|
||||
|
||||
Reference in New Issue
Block a user