package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -26,16 +26,16 @@ use Symfony\Contracts\Service\ResetInterface;
*/
class Profiler implements ResetInterface
{
private $storage;
private ProfilerStorageInterface $storage;
/**
* @var DataCollectorInterface[]
*/
private $collectors = [];
private array $collectors = [];
private $logger;
private $initiallyEnabled = true;
private $enabled = true;
private ?LoggerInterface $logger;
private bool $initiallyEnabled = true;
private bool $enabled = true;
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, bool $enable = true)
{
@@ -60,12 +60,15 @@ class Profiler implements ResetInterface
$this->enabled = true;
}
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Loads the Profile for the given Response.
*
* @return Profile|null
*/
public function loadProfileFromResponse(Response $response)
public function loadProfileFromResponse(Response $response): ?Profile
{
if (!$token = $response->headers->get('X-Debug-Token')) {
return null;
@@ -76,20 +79,16 @@ class Profiler implements ResetInterface
/**
* Loads the Profile for the given token.
*
* @return Profile|null
*/
public function loadProfile(string $token)
public function loadProfile(string $token): ?Profile
{
return $this->storage->read($token);
}
/**
* Saves a Profile.
*
* @return bool
*/
public function saveProfile(Profile $profile)
public function saveProfile(Profile $profile): bool
{
// late collect
foreach ($profile->getCollectors() as $collector) {
@@ -120,21 +119,17 @@ class Profiler implements ResetInterface
* @param string|null $start The start date to search from
* @param string|null $end The end date to search to
*
* @return array
*
* @see https://php.net/datetime.formats for the supported date/time formats
*/
public function find(?string $ip, ?string $url, ?string $limit, ?string $method, ?string $start, ?string $end, string $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.
*
* @return Profile|null
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null): ?Profile
{
if (false === $this->enabled) {
return null;
@@ -147,7 +142,7 @@ class Profiler implements ResetInterface
$profile->setStatusCode($response->getStatusCode());
try {
$profile->setIp($request->getClientIp());
} catch (ConflictingHeadersException $e) {
} catch (ConflictingHeadersException) {
$profile->setIp('Unknown');
}
@@ -177,10 +172,8 @@ class Profiler implements ResetInterface
/**
* Gets the Collectors associated with this profiler.
*
* @return array
*/
public function all()
public function all(): array
{
return $this->collectors;
}
@@ -210,10 +203,8 @@ class Profiler implements ResetInterface
* Returns true if a Collector for the given name exists.
*
* @param string $name A collector name
*
* @return bool
*/
public function has(string $name)
public function has(string $name): bool
{
return isset($this->collectors[$name]);
}
@@ -223,11 +214,9 @@ class Profiler implements ResetInterface
*
* @param string $name A collector name
*
* @return DataCollectorInterface
*
* @throws \InvalidArgumentException if the collector does not exist
*/
public function get(string $name)
public function get(string $name): DataCollectorInterface
{
if (!isset($this->collectors[$name])) {
throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
@@ -243,8 +232,8 @@ class Profiler implements ResetInterface
}
try {
$value = new \DateTime(is_numeric($value) ? '@'.$value : $value);
} catch (\Exception $e) {
$value = new \DateTimeImmutable(is_numeric($value) ? '@'.$value : $value);
} catch (\Exception) {
return null;
}