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

Open in your IDE?
  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.     /**
  24.      * @var KernelInterface
  25.      */
  26.     private $kernel;
  27.     /**
  28.      * Sets the Kernel associated with this Request.
  29.      */
  30.     public function setKernel(KernelInterface $kernel null)
  31.     {
  32.         $this->kernel $kernel;
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function collect(Request $requestResponse $response\Throwable $exception null)
  38.     {
  39.         $eom \DateTime::createFromFormat('d/m/Y''01/'.Kernel::END_OF_MAINTENANCE);
  40.         $eol \DateTime::createFromFormat('d/m/Y''01/'.Kernel::END_OF_LIFE);
  41.         $this->data = [
  42.             'token' => $response->headers->get('X-Debug-Token'),
  43.             'symfony_version' => Kernel::VERSION,
  44.             'symfony_minor_version' => sprintf('%s.%s'Kernel::MAJOR_VERSIONKernel::MINOR_VERSION),
  45.             'symfony_lts' => === Kernel::MINOR_VERSION,
  46.             'symfony_state' => $this->determineSymfonyState(),
  47.             'symfony_eom' => $eom->format('F Y'),
  48.             'symfony_eol' => $eol->format('F Y'),
  49.             'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
  50.             'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
  51.             'php_version' => \PHP_VERSION,
  52.             'php_architecture' => \PHP_INT_SIZE 8,
  53.             'php_intl_locale' => class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
  54.             'php_timezone' => date_default_timezone_get(),
  55.             'xdebug_enabled' => \extension_loaded('xdebug'),
  56.             'apcu_enabled' => \extension_loaded('apcu') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN),
  57.             'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN),
  58.             'bundles' => [],
  59.             'sapi_name' => \PHP_SAPI,
  60.         ];
  61.         if (isset($this->kernel)) {
  62.             foreach ($this->kernel->getBundles() as $name => $bundle) {
  63.                 $this->data['bundles'][$name] = new ClassStub(\get_class($bundle));
  64.             }
  65.         }
  66.         if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~'$this->data['php_version'], $matches) && isset($matches[2])) {
  67.             $this->data['php_version'] = $matches[1];
  68.             $this->data['php_version_extra'] = $matches[2];
  69.         }
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      */
  74.     public function reset()
  75.     {
  76.         $this->data = [];
  77.     }
  78.     public function lateCollect()
  79.     {
  80.         $this->data $this->cloneVar($this->data);
  81.     }
  82.     /**
  83.      * Gets the token.
  84.      */
  85.     public function getToken(): ?string
  86.     {
  87.         return $this->data['token'];
  88.     }
  89.     /**
  90.      * Gets the Symfony version.
  91.      */
  92.     public function getSymfonyVersion(): string
  93.     {
  94.         return $this->data['symfony_version'];
  95.     }
  96.     /**
  97.      * Returns the state of the current Symfony release.
  98.      *
  99.      * @return string One of: unknown, dev, stable, eom, eol
  100.      */
  101.     public function getSymfonyState(): string
  102.     {
  103.         return $this->data['symfony_state'];
  104.     }
  105.     /**
  106.      * Returns the minor Symfony version used (without patch numbers of extra
  107.      * suffix like "RC", "beta", etc.).
  108.      */
  109.     public function getSymfonyMinorVersion(): string
  110.     {
  111.         return $this->data['symfony_minor_version'];
  112.     }
  113.     /**
  114.      * Returns if the current Symfony version is a Long-Term Support one.
  115.      */
  116.     public function isSymfonyLts(): bool
  117.     {
  118.         return $this->data['symfony_lts'];
  119.     }
  120.     /**
  121.      * Returns the human readable date when this Symfony version ends its
  122.      * maintenance period.
  123.      */
  124.     public function getSymfonyEom(): string
  125.     {
  126.         return $this->data['symfony_eom'];
  127.     }
  128.     /**
  129.      * Returns the human readable date when this Symfony version reaches its
  130.      * "end of life" and won't receive bugs or security fixes.
  131.      */
  132.     public function getSymfonyEol(): string
  133.     {
  134.         return $this->data['symfony_eol'];
  135.     }
  136.     /**
  137.      * Gets the PHP version.
  138.      */
  139.     public function getPhpVersion(): string
  140.     {
  141.         return $this->data['php_version'];
  142.     }
  143.     /**
  144.      * Gets the PHP version extra part.
  145.      */
  146.     public function getPhpVersionExtra(): ?string
  147.     {
  148.         return $this->data['php_version_extra'] ?? null;
  149.     }
  150.     /**
  151.      * @return int The PHP architecture as number of bits (e.g. 32 or 64)
  152.      */
  153.     public function getPhpArchitecture(): int
  154.     {
  155.         return $this->data['php_architecture'];
  156.     }
  157.     public function getPhpIntlLocale(): string
  158.     {
  159.         return $this->data['php_intl_locale'];
  160.     }
  161.     public function getPhpTimezone(): string
  162.     {
  163.         return $this->data['php_timezone'];
  164.     }
  165.     /**
  166.      * Gets the environment.
  167.      */
  168.     public function getEnv(): string
  169.     {
  170.         return $this->data['env'];
  171.     }
  172.     /**
  173.      * Returns true if the debug is enabled.
  174.      *
  175.      * @return bool|string true if debug is enabled, false otherwise or a string if no kernel was set
  176.      */
  177.     public function isDebug()
  178.     {
  179.         return $this->data['debug'];
  180.     }
  181.     /**
  182.      * Returns true if the XDebug is enabled.
  183.      */
  184.     public function hasXDebug(): bool
  185.     {
  186.         return $this->data['xdebug_enabled'];
  187.     }
  188.     /**
  189.      * Returns true if APCu is enabled.
  190.      */
  191.     public function hasApcu(): bool
  192.     {
  193.         return $this->data['apcu_enabled'];
  194.     }
  195.     /**
  196.      * Returns true if Zend OPcache is enabled.
  197.      */
  198.     public function hasZendOpcache(): bool
  199.     {
  200.         return $this->data['zend_opcache_enabled'];
  201.     }
  202.     public function getBundles()
  203.     {
  204.         return $this->data['bundles'];
  205.     }
  206.     /**
  207.      * Gets the PHP SAPI name.
  208.      */
  209.     public function getSapiName(): string
  210.     {
  211.         return $this->data['sapi_name'];
  212.     }
  213.     /**
  214.      * {@inheritdoc}
  215.      */
  216.     public function getName(): string
  217.     {
  218.         return 'config';
  219.     }
  220.     /**
  221.      * Tries to retrieve information about the current Symfony version.
  222.      *
  223.      * @return string One of: dev, stable, eom, eol
  224.      */
  225.     private function determineSymfonyState(): string
  226.     {
  227.         $now = new \DateTime();
  228.         $eom \DateTime::createFromFormat('d/m/Y''01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
  229.         $eol \DateTime::createFromFormat('d/m/Y''01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
  230.         if ($now $eol) {
  231.             $versionState 'eol';
  232.         } elseif ($now $eom) {
  233.             $versionState 'eom';
  234.         } elseif ('' !== Kernel::EXTRA_VERSION) {
  235.             $versionState 'dev';
  236.         } else {
  237.             $versionState 'stable';
  238.         }
  239.         return $versionState;
  240.     }
  241. }