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

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.     private $kernel;
  24.     /**
  25.      * Sets the Kernel associated with this Request.
  26.      */
  27.     public function setKernel(KernelInterface $kernel = null)
  28.     {
  29.         $this->kernel = $kernel;
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function collect(Request $request, Response $response, \Throwable $exception = null)
  35.     {
  36.         $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
  37.         $eol = \DateTime::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_VERSION, Kernel::MINOR_VERSION),
  42.             'symfony_lts' => 4 === 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_BOOLEAN),
  54.             'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN),
  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(\get_class($bundle));
  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.     /**
  69.      * {@inheritdoc}
  70.      */
  71.     public function reset()
  72.     {
  73.         $this->data = [];
  74.     }
  75.     public function lateCollect()
  76.     {
  77.         $this->data = $this->cloneVar($this->data);
  78.     }
  79.     /**
  80.      * Gets the token.
  81.      */
  82.     public function getToken(): ?string
  83.     {
  84.         return $this->data['token'];
  85.     }
  86.     /**
  87.      * Gets the Symfony version.
  88.      */
  89.     public function getSymfonyVersion(): string
  90.     {
  91.         return $this->data['symfony_version'];
  92.     }
  93.     /**
  94.      * Returns the state of the current Symfony release
  95.      * as one of: unknown, dev, stable, eom, eol.
  96.      */
  97.     public function getSymfonyState(): string
  98.     {
  99.         return $this->data['symfony_state'];
  100.     }
  101.     /**
  102.      * Returns the minor Symfony version used (without patch numbers of extra
  103.      * suffix like "RC", "beta", etc.).
  104.      */
  105.     public function getSymfonyMinorVersion(): string
  106.     {
  107.         return $this->data['symfony_minor_version'];
  108.     }
  109.     public function isSymfonyLts(): bool
  110.     {
  111.         return $this->data['symfony_lts'];
  112.     }
  113.     /**
  114.      * Returns the human readable date when this Symfony version ends its
  115.      * maintenance period.
  116.      */
  117.     public function getSymfonyEom(): string
  118.     {
  119.         return $this->data['symfony_eom'];
  120.     }
  121.     /**
  122.      * Returns the human readable date when this Symfony version reaches its
  123.      * "end of life" and won't receive bugs or security fixes.
  124.      */
  125.     public function getSymfonyEol(): string
  126.     {
  127.         return $this->data['symfony_eol'];
  128.     }
  129.     /**
  130.      * Gets the PHP version.
  131.      */
  132.     public function getPhpVersion(): string
  133.     {
  134.         return $this->data['php_version'];
  135.     }
  136.     /**
  137.      * Gets the PHP version extra part.
  138.      */
  139.     public function getPhpVersionExtra(): ?string
  140.     {
  141.         return $this->data['php_version_extra'] ?? null;
  142.     }
  143.     public function getPhpArchitecture(): int
  144.     {
  145.         return $this->data['php_architecture'];
  146.     }
  147.     public function getPhpIntlLocale(): string
  148.     {
  149.         return $this->data['php_intl_locale'];
  150.     }
  151.     public function getPhpTimezone(): string
  152.     {
  153.         return $this->data['php_timezone'];
  154.     }
  155.     /**
  156.      * Gets the environment.
  157.      */
  158.     public function getEnv(): string
  159.     {
  160.         return $this->data['env'];
  161.     }
  162.     /**
  163.      * Returns true if the debug is enabled.
  164.      *
  165.      * @return bool|string true if debug is enabled, false otherwise or a string if no kernel was set
  166.      */
  167.     public function isDebug(): bool|string
  168.     {
  169.         return $this->data['debug'];
  170.     }
  171.     /**
  172.      * Returns true if the XDebug is enabled.
  173.      */
  174.     public function hasXDebug(): bool
  175.     {
  176.         return $this->data['xdebug_enabled'];
  177.     }
  178.     /**
  179.      * Returns true if APCu is enabled.
  180.      */
  181.     public function hasApcu(): bool
  182.     {
  183.         return $this->data['apcu_enabled'];
  184.     }
  185.     /**
  186.      * Returns true if Zend OPcache is enabled.
  187.      */
  188.     public function hasZendOpcache(): bool
  189.     {
  190.         return $this->data['zend_opcache_enabled'];
  191.     }
  192.     public function getBundles()
  193.     {
  194.         return $this->data['bundles'];
  195.     }
  196.     /**
  197.      * Gets the PHP SAPI name.
  198.      */
  199.     public function getSapiName(): string
  200.     {
  201.         return $this->data['sapi_name'];
  202.     }
  203.     /**
  204.      * {@inheritdoc}
  205.      */
  206.     public function getName(): string
  207.     {
  208.         return 'config';
  209.     }
  210.     private function determineSymfonyState(): string
  211.     {
  212.         $now = new \DateTime();
  213.         $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
  214.         $eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
  215.         if ($now > $eol) {
  216.             $versionState = 'eol';
  217.         } elseif ($now > $eom) {
  218.             $versionState = 'eom';
  219.         } elseif ('' !== Kernel::EXTRA_VERSION) {
  220.             $versionState = 'dev';
  221.         } else {
  222.             $versionState = 'stable';
  223.         }
  224.         return $versionState;
  225.     }
  226. }