vendor/symfony/http-kernel/DataCollector/ConfigDataCollector.php line 32

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel\DataCollector;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\Kernel;
  14. use Symfony\Component\HttpKernel\KernelInterface;
  15. use Symfony\Component\VarDumper\Caster\ClassStub;
  16. /**
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  *
  19.  * @final
  20.  */
  21. class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
  22. {
  23.     private KernelInterface $kernel;
  24.     /**
  25.      * Sets the Kernel associated with this Request.
  26.      */
  27.     public function setKernel(KernelInterface $kernel null)
  28.     {
  29.         if (\func_num_args()) {
  30.             trigger_deprecation('symfony/http-kernel''6.2''Calling "%s()" without any arguments is deprecated, pass null explicitly instead.'__METHOD__);
  31.         }
  32.         $this->kernel $kernel;
  33.     }
  34.     public function collect(Request $requestResponse $response\Throwable $exception null)
  35.     {
  36.         $eom \DateTimeImmutable::createFromFormat('d/m/Y''01/'.Kernel::END_OF_MAINTENANCE);
  37.         $eol \DateTimeImmutable::createFromFormat('d/m/Y''01/'.Kernel::END_OF_LIFE);
  38.         $this->data = [
  39.             'token' => $response->headers->get('X-Debug-Token'),
  40.             'symfony_version' => Kernel::VERSION,
  41.             'symfony_minor_version' => sprintf('%s.%s'Kernel::MAJOR_VERSIONKernel::MINOR_VERSION),
  42.             'symfony_lts' => === Kernel::MINOR_VERSION,
  43.             'symfony_state' => $this->determineSymfonyState(),
  44.             'symfony_eom' => $eom->format('F Y'),
  45.             'symfony_eol' => $eol->format('F Y'),
  46.             'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
  47.             'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
  48.             'php_version' => \PHP_VERSION,
  49.             'php_architecture' => \PHP_INT_SIZE 8,
  50.             'php_intl_locale' => class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
  51.             'php_timezone' => date_default_timezone_get(),
  52.             'xdebug_enabled' => \extension_loaded('xdebug'),
  53.             'apcu_enabled' => \extension_loaded('apcu') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL),
  54.             'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL),
  55.             'bundles' => [],
  56.             'sapi_name' => \PHP_SAPI,
  57.         ];
  58.         if (isset($this->kernel)) {
  59.             foreach ($this->kernel->getBundles() as $name => $bundle) {
  60.                 $this->data['bundles'][$name] = new ClassStub($bundle::class);
  61.             }
  62.         }
  63.         if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~'$this->data['php_version'], $matches) && isset($matches[2])) {
  64.             $this->data['php_version'] = $matches[1];
  65.             $this->data['php_version_extra'] = $matches[2];
  66.         }
  67.     }
  68.     public function reset()
  69.     {
  70.         $this->data = [];
  71.     }
  72.     public function lateCollect()
  73.     {
  74.         $this->data $this->cloneVar($this->data);
  75.     }
  76.     /**
  77.      * Gets the token.
  78.      */
  79.     public function getToken(): ?string
  80.     {
  81.         return $this->data['token'];
  82.     }
  83.     /**
  84.      * Gets the Symfony version.
  85.      */
  86.     public function getSymfonyVersion(): string
  87.     {
  88.         return $this->data['symfony_version'];
  89.     }
  90.     /**
  91.      * Returns the state of the current Symfony release
  92.      * as one of: unknown, dev, stable, eom, eol.
  93.      */
  94.     public function getSymfonyState(): string
  95.     {
  96.         return $this->data['symfony_state'];
  97.     }
  98.     /**
  99.      * Returns the minor Symfony version used (without patch numbers of extra
  100.      * suffix like "RC", "beta", etc.).
  101.      */
  102.     public function getSymfonyMinorVersion(): string
  103.     {
  104.         return $this->data['symfony_minor_version'];
  105.     }
  106.     public function isSymfonyLts(): bool
  107.     {
  108.         return $this->data['symfony_lts'];
  109.     }
  110.     /**
  111.      * Returns the human readable date when this Symfony version ends its
  112.      * maintenance period.
  113.      */
  114.     public function getSymfonyEom(): string
  115.     {
  116.         return $this->data['symfony_eom'];
  117.     }
  118.     /**
  119.      * Returns the human readable date when this Symfony version reaches its
  120.      * "end of life" and won't receive bugs or security fixes.
  121.      */
  122.     public function getSymfonyEol(): string
  123.     {
  124.         return $this->data['symfony_eol'];
  125.     }
  126.     /**
  127.      * Gets the PHP version.
  128.      */
  129.     public function getPhpVersion(): string
  130.     {
  131.         return $this->data['php_version'];
  132.     }
  133.     /**
  134.      * Gets the PHP version extra part.
  135.      */
  136.     public function getPhpVersionExtra(): ?string
  137.     {
  138.         return $this->data['php_version_extra'] ?? null;
  139.     }
  140.     public function getPhpArchitecture(): int
  141.     {
  142.         return $this->data['php_architecture'];
  143.     }
  144.     public function getPhpIntlLocale(): string
  145.     {
  146.         return $this->data['php_intl_locale'];
  147.     }
  148.     public function getPhpTimezone(): string
  149.     {
  150.         return $this->data['php_timezone'];
  151.     }
  152.     /**
  153.      * Gets the environment.
  154.      */
  155.     public function getEnv(): string
  156.     {
  157.         return $this->data['env'];
  158.     }
  159.     /**
  160.      * Returns true if the debug is enabled.
  161.      *
  162.      * @return bool|string true if debug is enabled, false otherwise or a string if no kernel was set
  163.      */
  164.     public function isDebug(): bool|string
  165.     {
  166.         return $this->data['debug'];
  167.     }
  168.     /**
  169.      * Returns true if the Xdebug is enabled.
  170.      */
  171.     public function hasXdebug(): bool
  172.     {
  173.         return $this->data['xdebug_enabled'];
  174.     }
  175.     /**
  176.      * Returns true if the function xdebug_info is available.
  177.      */
  178.     public function hasXdebugInfo(): bool
  179.     {
  180.         return \function_exists('xdebug_info');
  181.     }
  182.     /**
  183.      * Returns true if APCu is enabled.
  184.      */
  185.     public function hasApcu(): bool
  186.     {
  187.         return $this->data['apcu_enabled'];
  188.     }
  189.     /**
  190.      * Returns true if Zend OPcache is enabled.
  191.      */
  192.     public function hasZendOpcache(): bool
  193.     {
  194.         return $this->data['zend_opcache_enabled'];
  195.     }
  196.     public function getBundles()
  197.     {
  198.         return $this->data['bundles'];
  199.     }
  200.     /**
  201.      * Gets the PHP SAPI name.
  202.      */
  203.     public function getSapiName(): string
  204.     {
  205.         return $this->data['sapi_name'];
  206.     }
  207.     public function getName(): string
  208.     {
  209.         return 'config';
  210.     }
  211.     private function determineSymfonyState(): string
  212.     {
  213.         $now = new \DateTimeImmutable();
  214.         $eom \DateTimeImmutable::createFromFormat('d/m/Y''01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
  215.         $eol \DateTimeImmutable::createFromFormat('d/m/Y''01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
  216.         if ($now $eol) {
  217.             $versionState 'eol';
  218.         } elseif ($now $eom) {
  219.             $versionState 'eom';
  220.         } elseif ('' !== Kernel::EXTRA_VERSION) {
  221.             $versionState 'dev';
  222.         } else {
  223.             $versionState 'stable';
  224.         }
  225.         return $versionState;
  226.     }
  227. }