Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -11,50 +11,37 @@
namespace Symfony\Component\HttpKernel\Profiler;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
* Profiler.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Profiler
class Profiler implements ResetInterface
{
/**
* @var ProfilerStorageInterface
*/
private $storage;
/**
* @var DataCollectorInterface[]
*/
private $collectors = array();
private array $collectors = [];
/**
* @var LoggerInterface
*/
private $logger;
private bool $initiallyEnabled = true;
private bool $enabled = true;
/**
* @var bool
*/
private $enabled = true;
/**
* Constructor.
*
* @param ProfilerStorageInterface $storage A ProfilerStorageInterface instance
* @param LoggerInterface $logger A LoggerInterface instance
*/
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null)
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, bool $enable = true)
{
$this->storage = $storage;
$this->logger = $logger;
$this->initiallyEnabled = $this->enabled = $enable;
}
/**
@@ -75,15 +62,11 @@ class Profiler
/**
* Loads the Profile for the given Response.
*
* @param Response $response A Response instance
*
* @return Profile|false A Profile instance
*/
public function loadProfileFromResponse(Response $response)
public function loadProfileFromResponse(Response $response): ?Profile
{
if (!$token = $response->headers->get('X-Debug-Token')) {
return false;
return null;
}
return $this->loadProfile($token);
@@ -91,24 +74,16 @@ class Profiler
/**
* Loads the Profile for the given token.
*
* @param string $token A token
*
* @return Profile A Profile instance
*/
public function loadProfile($token)
public function loadProfile(string $token): ?Profile
{
return $this->storage->read($token);
}
/**
* Saves a Profile.
*
* @param Profile $profile A Profile instance
*
* @return bool
*/
public function saveProfile(Profile $profile)
public function saveProfile(Profile $profile): bool
{
// late collect
foreach ($profile->getCollectors() as $collector) {
@@ -118,7 +93,7 @@ class Profiler
}
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;
@@ -135,36 +110,24 @@ class Profiler
/**
* 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
*
* @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): array
{
return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode);
}
/**
* Collects data for the given Response.
*
* @param Request $request A Request instance
* @param Response $response A Response instance
* @param \Exception $exception An exception instance if the request threw one
*
* @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): ?Profile
{
if (false === $this->enabled) {
return;
return null;
}
$profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
@@ -178,6 +141,10 @@ class Profiler
$profile->setIp('Unknown');
}
if ($prevToken = $response->headers->get('X-Debug-Token')) {
$response->headers->set('X-Previous-Debug-Token', $prevToken);
}
$response->headers->set('X-Debug-Token', $profile->getToken());
foreach ($this->collectors as $collector) {
@@ -190,12 +157,18 @@ class Profiler
return $profile;
}
public function reset()
{
foreach ($this->collectors as $collector) {
$collector->reset();
}
$this->enabled = $this->initiallyEnabled;
}
/**
* Gets the Collectors associated with this profiler.
*
* @return array An array of collectors
*/
public function all()
public function all(): array
{
return $this->collectors;
}
@@ -205,9 +178,9 @@ class Profiler
*
* @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);
}
@@ -215,8 +188,6 @@ class Profiler
/**
* Adds a Collector.
*
* @param DataCollectorInterface $collector A DataCollectorInterface instance
*/
public function add(DataCollectorInterface $collector)
{
@@ -227,10 +198,8 @@ class Profiler
* Returns true if a Collector for the given name exists.
*
* @param string $name A collector name
*
* @return bool
*/
public function has($name)
public function has(string $name): bool
{
return isset($this->collectors[$name]);
}
@@ -240,11 +209,9 @@ class Profiler
*
* @param string $name A collector name
*
* @return DataCollectorInterface A DataCollectorInterface instance
*
* @throws \InvalidArgumentException if the collector does not exist
*/
public function get($name)
public function get(string $name): DataCollectorInterface
{
if (!isset($this->collectors[$name])) {
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
@@ -253,16 +220,16 @@ class Profiler
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();