updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -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,24 +47,24 @@ class FileProfilerStorage implements ProfilerStorageInterface
/**
* {@inheritdoc}
*/
public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null)
public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null): array
{
$file = $this->getIndexFilename();
if (!file_exists($file)) {
return array();
return [];
}
$file = fopen($file, 'r');
fseek($file, 0, SEEK_END);
fseek($file, 0, \SEEK_END);
$result = array();
$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;
}
@@ -76,7 +76,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
continue;
}
$result[$csvToken] = array(
$result[$csvToken] = [
'token' => $csvToken,
'ip' => $csvIp,
'method' => $csvMethod,
@@ -84,7 +84,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
'time' => $csvTime,
'parent' => $csvParent,
'status_code' => $csvStatusCode,
);
];
}
fclose($file);
@@ -113,13 +113,9 @@ class FileProfilerStorage implements ProfilerStorageInterface
/**
* {@inheritdoc}
*/
public function read($token)
public function read($token): ?Profile
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return;
}
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
return $this->doRead($token);
}
/**
@@ -127,7 +123,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
*
* @throws \RuntimeException
*/
public function write(Profile $profile)
public function write(Profile $profile): bool
{
$file = $this->getFilename($profile->getToken());
@@ -149,7 +145,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
}, $profile->getChildren()));
// Store profile
$data = array(
$data = [
'token' => $profileToken,
'parent' => $parentToken,
'children' => $childrenToken,
@@ -159,9 +155,15 @@ class FileProfilerStorage implements ProfilerStorageInterface
'url' => $profile->getUrl(),
'time' => $profile->getTime(),
'status_code' => $profile->getStatusCode(),
);
];
if (false === file_put_contents($file, serialize($data))) {
$data = serialize($data);
if (\function_exists('gzencode')) {
$data = gzencode($data, 3);
}
if (false === file_put_contents($file, $data, \LOCK_EX)) {
return false;
}
@@ -171,7 +173,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
return false;
}
fputcsv($file, array(
fputcsv($file, [
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
@@ -179,7 +181,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$profile->getTime(),
$profile->getParentToken(),
$profile->getStatusCode(),
));
]);
fclose($file);
}
@@ -227,7 +229,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$position = ftell($file);
if (0 === $position) {
return;
return null;
}
while (true) {
@@ -249,7 +251,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;
@@ -278,13 +280,34 @@ class FileProfilerStorage implements ProfilerStorageInterface
}
foreach ($data['children'] as $token) {
if (!$token || !file_exists($file = $this->getFilename($token))) {
continue;
if (null !== $childProfile = $this->doRead($token, $profile)) {
$profile->addChild($childProfile);
}
$profile->addChild($this->createProfileFromData($token, unserialize(file_get_contents($file)), $profile));
}
return $profile;
}
private function doRead($token, Profile $profile = null): ?Profile
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return null;
}
$h = fopen($file, 'r');
flock($h, \LOCK_SH);
$data = stream_get_contents($h);
flock($h, \LOCK_UN);
fclose($h);
if (\function_exists('gzdecode')) {
$data = @gzdecode($data) ?: $data;
}
if (!$data = unserialize($data)) {
return null;
}
return $this->createProfileFromData($token, $data, $profile);
}
}

View File

@@ -25,7 +25,7 @@ class Profile
/**
* @var DataCollectorInterface[]
*/
private $collectors = array();
private $collectors = [];
private $ip;
private $method;
@@ -41,7 +41,7 @@ class Profile
/**
* @var Profile[]
*/
private $children = array();
private $children = [];
public function __construct(string $token)
{
@@ -99,7 +99,7 @@ class Profile
/**
* Returns the IP.
*
* @return string The IP
* @return string|null The IP
*/
public function getIp()
{
@@ -119,7 +119,7 @@ class Profile
/**
* Returns the request method.
*
* @return string The request method
* @return string|null The request method
*/
public function getMethod()
{
@@ -134,13 +134,16 @@ class Profile
/**
* Returns the URL.
*
* @return string The URL
* @return string|null The URL
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl($url)
{
$this->url = $url;
@@ -153,11 +156,7 @@ class Profile
*/
public function getTime()
{
if (null === $this->time) {
return 0;
}
return $this->time;
return $this->time ?? 0;
}
/**
@@ -177,7 +176,7 @@ class Profile
}
/**
* @return int
* @return int|null
*/
public function getStatusCode()
{
@@ -201,7 +200,7 @@ class Profile
*/
public function setChildren(array $children)
{
$this->children = array();
$this->children = [];
foreach ($children as $child) {
$this->addChild($child);
}
@@ -262,7 +261,7 @@ class Profile
*/
public function setCollectors(array $collectors)
{
$this->collectors = array();
$this->collectors = [];
foreach ($collectors as $collector) {
$this->addCollector($collector);
}
@@ -288,8 +287,11 @@ class Profile
return isset($this->collectors[$name]);
}
/**
* @return array
*/
public function __sleep()
{
return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode');
return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode'];
}
}

View File

@@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Profiler;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -31,7 +32,7 @@ class Profiler implements ResetInterface
/**
* @var DataCollectorInterface[]
*/
private $collectors = array();
private $collectors = [];
private $logger;
private $initiallyEnabled = true;
@@ -63,12 +64,12 @@ class Profiler implements ResetInterface
/**
* Loads the Profile for the given Response.
*
* @return Profile|false A Profile instance
* @return Profile|null A Profile instance
*/
public function loadProfileFromResponse(Response $response)
{
if (!$token = $response->headers->get('X-Debug-Token')) {
return false;
return null;
}
return $this->loadProfile($token);
@@ -79,7 +80,7 @@ class Profiler implements ResetInterface
*
* @param string $token A token
*
* @return Profile A Profile instance
* @return Profile|null A Profile instance
*/
public function loadProfile($token)
{
@@ -101,7 +102,7 @@ class Profiler implements ResetInterface
}
if (!($ret = $this->storage->write($profile)) && null !== $this->logger) {
$this->logger->warning('Unable to store the profiler information.', array('configured_storage' => \get_class($this->storage)));
$this->logger->warning('Unable to store the profiler information.', ['configured_storage' => \get_class($this->storage)]);
}
return $ret;
@@ -128,7 +129,7 @@ class Profiler implements ResetInterface
*
* @return array An array of tokens
*
* @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)
{
@@ -138,12 +139,16 @@ class Profiler implements ResetInterface
/**
* Collects data for the given Response.
*
* @param \Throwable|null $exception
*
* @return Profile|null A Profile instance or null if the profiler is disabled
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/* , \Throwable $exception = null */)
{
$exception = 2 < \func_num_args() ? func_get_arg(2) : null;
if (false === $this->enabled) {
return;
return null;
}
$profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
@@ -163,9 +168,14 @@ class Profiler implements ResetInterface
$response->headers->set('X-Debug-Token', $profile->getToken());
$wrappedException = null;
foreach ($this->collectors as $collector) {
$collector->collect($request, $response, $exception);
if (($e = $exception) instanceof \Error) {
$r = new \ReflectionMethod($collector, 'collect');
$e = 2 >= $r->getNumberOfParameters() || !($p = $r->getParameters()[2])->hasType() || \Exception::class !== $p->getType()->getName() ? $e : ($wrappedException ?? $wrappedException = new FatalThrowableError($e));
}
$collector->collect($request, $response, $e);
// we need to clone for sub-requests
$profile->addCollector(clone $collector);
}
@@ -196,9 +206,9 @@ class Profiler implements ResetInterface
*
* @param DataCollectorInterface[] $collectors An array of collectors
*/
public function set(array $collectors = array())
public function set(array $collectors = [])
{
$this->collectors = array();
$this->collectors = [];
foreach ($collectors as $collector) {
$this->add($collector);
}
@@ -242,16 +252,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();

View File

@@ -38,7 +38,7 @@ interface ProfilerStorageInterface
*
* @return array An array of tokens
*/
public function find($ip, $url, $limit, $method, $start = null, $end = null);
public function find($ip, $url, $limit, $method, $start = null, $end = null): array;
/**
* Reads data associated with the given token.
@@ -47,16 +47,16 @@ interface ProfilerStorageInterface
*
* @param string $token A token
*
* @return Profile The profile associated with token
* @return Profile|null The profile associated with token
*/
public function read($token);
public function read($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.