mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-02 04:59:49 +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;
|
||||
|
||||
67
vendor/symfony/http-kernel/Profiler/Profile.php
vendored
67
vendor/symfony/http-kernel/Profiler/Profile.php
vendored
@@ -48,12 +48,7 @@ class Profile
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the token.
|
||||
*
|
||||
* @param string $token The token
|
||||
*/
|
||||
public function setToken($token)
|
||||
public function setToken(string $token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
@@ -61,7 +56,7 @@ class Profile
|
||||
/**
|
||||
* Gets the token.
|
||||
*
|
||||
* @return string The token
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
@@ -79,7 +74,7 @@ class Profile
|
||||
/**
|
||||
* Returns the parent profile.
|
||||
*
|
||||
* @return self
|
||||
* @return self|null
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
@@ -89,7 +84,7 @@ class Profile
|
||||
/**
|
||||
* Returns the parent token.
|
||||
*
|
||||
* @return string|null The parent token
|
||||
* @return string|null
|
||||
*/
|
||||
public function getParentToken()
|
||||
{
|
||||
@@ -99,19 +94,14 @@ class Profile
|
||||
/**
|
||||
* Returns the IP.
|
||||
*
|
||||
* @return string The IP
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIp()
|
||||
{
|
||||
return $this->ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IP.
|
||||
*
|
||||
* @param string $ip
|
||||
*/
|
||||
public function setIp($ip)
|
||||
public function setIp(?string $ip)
|
||||
{
|
||||
$this->ip = $ip;
|
||||
}
|
||||
@@ -119,14 +109,14 @@ class Profile
|
||||
/**
|
||||
* Returns the request method.
|
||||
*
|
||||
* @return string The request method
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function setMethod($method)
|
||||
public function setMethod(string $method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
@@ -134,50 +124,38 @@ class Profile
|
||||
/**
|
||||
* Returns the URL.
|
||||
*
|
||||
* @return string The URL
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
public function setUrl(?string $url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time.
|
||||
*
|
||||
* @return int The time
|
||||
* @return int
|
||||
*/
|
||||
public function getTime()
|
||||
{
|
||||
if (null === $this->time) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->time;
|
||||
return $this->time ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $time The time
|
||||
*/
|
||||
public function setTime($time)
|
||||
public function setTime(int $time)
|
||||
{
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $statusCode
|
||||
*/
|
||||
public function setStatusCode($statusCode)
|
||||
public function setStatusCode(int $statusCode)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return int|null
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
@@ -230,13 +208,11 @@ class Profile
|
||||
/**
|
||||
* Gets a Collector by name.
|
||||
*
|
||||
* @param string $name A collector name
|
||||
*
|
||||
* @return DataCollectorInterface A DataCollectorInterface instance
|
||||
* @return DataCollectorInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException if the collector does not exist
|
||||
*/
|
||||
public function getCollector($name)
|
||||
public function getCollector(string $name)
|
||||
{
|
||||
if (!isset($this->collectors[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
|
||||
@@ -277,17 +253,16 @@ class Profile
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a Collector for the given name exists.
|
||||
*
|
||||
* @param string $name A collector name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCollector($name)
|
||||
public function hasCollector(string $name)
|
||||
{
|
||||
return isset($this->collectors[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode'];
|
||||
|
||||
48
vendor/symfony/http-kernel/Profiler/Profiler.php
vendored
48
vendor/symfony/http-kernel/Profiler/Profiler.php
vendored
@@ -63,12 +63,12 @@ class Profiler implements ResetInterface
|
||||
/**
|
||||
* Loads the Profile for the given Response.
|
||||
*
|
||||
* @return Profile|false A Profile instance
|
||||
* @return Profile|null
|
||||
*/
|
||||
public function loadProfileFromResponse(Response $response)
|
||||
{
|
||||
if (!$token = $response->headers->get('X-Debug-Token')) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->loadProfile($token);
|
||||
@@ -77,11 +77,9 @@ class Profiler implements ResetInterface
|
||||
/**
|
||||
* Loads the Profile for the given token.
|
||||
*
|
||||
* @param string $token A token
|
||||
*
|
||||
* @return Profile A Profile instance
|
||||
* @return Profile|null
|
||||
*/
|
||||
public function loadProfile($token)
|
||||
public function loadProfile(string $token)
|
||||
{
|
||||
return $this->storage->read($token);
|
||||
}
|
||||
@@ -118,19 +116,15 @@ class Profiler implements ResetInterface
|
||||
/**
|
||||
* Finds profiler tokens for the given criteria.
|
||||
*
|
||||
* @param string $ip The IP
|
||||
* @param string $url The URL
|
||||
* @param string $limit The maximum number of tokens to return
|
||||
* @param string $method The request method
|
||||
* @param string $start The start date to search from
|
||||
* @param string $end The end date to search to
|
||||
* @param string $statusCode The request status code
|
||||
* @param string|null $limit The maximum number of tokens to return
|
||||
* @param string|null $start The start date to search from
|
||||
* @param string|null $end The end date to search to
|
||||
*
|
||||
* @return array An array of tokens
|
||||
* @return array
|
||||
*
|
||||
* @see http://php.net/manual/en/datetime.formats.php for the supported date/time formats
|
||||
* @see https://php.net/datetime.formats for the supported date/time formats
|
||||
*/
|
||||
public function find($ip, $url, $limit, $method, $start, $end, $statusCode = null)
|
||||
public function find(?string $ip, ?string $url, ?string $limit, ?string $method, ?string $start, ?string $end, string $statusCode = null)
|
||||
{
|
||||
return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode);
|
||||
}
|
||||
@@ -138,12 +132,12 @@ class Profiler implements ResetInterface
|
||||
/**
|
||||
* Collects data for the given Response.
|
||||
*
|
||||
* @return Profile|null A Profile instance or null if the profiler is disabled
|
||||
* @return Profile|null
|
||||
*/
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
public function collect(Request $request, Response $response, \Throwable $exception = null)
|
||||
{
|
||||
if (false === $this->enabled) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
|
||||
@@ -184,7 +178,7 @@ class Profiler implements ResetInterface
|
||||
/**
|
||||
* Gets the Collectors associated with this profiler.
|
||||
*
|
||||
* @return array An array of collectors
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
@@ -219,7 +213,7 @@ class Profiler implements ResetInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has($name)
|
||||
public function has(string $name)
|
||||
{
|
||||
return isset($this->collectors[$name]);
|
||||
}
|
||||
@@ -229,11 +223,11 @@ class Profiler implements ResetInterface
|
||||
*
|
||||
* @param string $name A collector name
|
||||
*
|
||||
* @return DataCollectorInterface A DataCollectorInterface instance
|
||||
* @return DataCollectorInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException if the collector does not exist
|
||||
*/
|
||||
public function get($name)
|
||||
public function get(string $name)
|
||||
{
|
||||
if (!isset($this->collectors[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
|
||||
@@ -242,16 +236,16 @@ class Profiler implements ResetInterface
|
||||
return $this->collectors[$name];
|
||||
}
|
||||
|
||||
private function getTimestamp($value)
|
||||
private function getTimestamp(?string $value): ?int
|
||||
{
|
||||
if (null === $value || '' == $value) {
|
||||
return;
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$value = new \DateTime(is_numeric($value) ? '@'.$value : $value);
|
||||
} catch (\Exception $e) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value->getTimestamp();
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Symfony\Component\HttpKernel\Profiler;
|
||||
* As the profiler must only be used on non-production servers, the file storage
|
||||
* is more than enough and no other implementations will ever be supported.
|
||||
*
|
||||
* @internal since 4.2
|
||||
* @internal
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
@@ -29,34 +29,23 @@ interface ProfilerStorageInterface
|
||||
/**
|
||||
* Finds profiler tokens for the given criteria.
|
||||
*
|
||||
* @param string $ip The IP
|
||||
* @param string $url The URL
|
||||
* @param string $limit The maximum number of tokens to return
|
||||
* @param string $method The request method
|
||||
* @param int|null $start The start date to search from
|
||||
* @param int|null $end The end date to search to
|
||||
*
|
||||
* @return array An array of tokens
|
||||
* @param int|null $limit The maximum number of tokens to return
|
||||
* @param int|null $start The start date to search from
|
||||
* @param int|null $end The end date to search to
|
||||
*/
|
||||
public function find($ip, $url, $limit, $method, $start = null, $end = null);
|
||||
public function find(?string $ip, ?string $url, ?int $limit, ?string $method, int $start = null, int $end = null): array;
|
||||
|
||||
/**
|
||||
* Reads data associated with the given token.
|
||||
*
|
||||
* The method returns false if the token does not exist in the storage.
|
||||
*
|
||||
* @param string $token A token
|
||||
*
|
||||
* @return Profile The profile associated with token
|
||||
*/
|
||||
public function read($token);
|
||||
public function read(string $token): ?Profile;
|
||||
|
||||
/**
|
||||
* Saves a Profile.
|
||||
*
|
||||
* @return bool Write operation successful
|
||||
*/
|
||||
public function write(Profile $profile);
|
||||
public function write(Profile $profile): bool;
|
||||
|
||||
/**
|
||||
* Purges all data from the database.
|
||||
|
||||
Reference in New Issue
Block a user