Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\DataCollector; Chris@0: Chris@0: use Symfony\Component\HttpFoundation\Request; Chris@0: use Symfony\Component\HttpFoundation\Response; Chris@17: use Symfony\Component\HttpKernel\Kernel; Chris@17: use Symfony\Component\HttpKernel\KernelInterface; Chris@14: use Symfony\Component\VarDumper\Caster\LinkStub; Chris@0: Chris@0: /** Chris@0: * @author Fabien Potencier Chris@0: */ Chris@14: class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface Chris@0: { Chris@0: /** Chris@0: * @var KernelInterface Chris@0: */ Chris@0: private $kernel; Chris@0: private $name; Chris@0: private $version; Chris@14: private $hasVarDumper; Chris@0: Chris@0: /** Chris@0: * @param string $name The name of the application using the web profiler Chris@0: * @param string $version The version of the application using the web profiler Chris@0: */ Chris@0: public function __construct($name = null, $version = null) Chris@0: { Chris@0: $this->name = $name; Chris@0: $this->version = $version; Chris@14: $this->hasVarDumper = class_exists(LinkStub::class); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the Kernel associated with this Request. Chris@0: */ Chris@0: public function setKernel(KernelInterface $kernel = null) Chris@0: { Chris@0: $this->kernel = $kernel; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function collect(Request $request, Response $response, \Exception $exception = null) Chris@0: { Chris@17: $this->data = [ Chris@0: 'app_name' => $this->name, Chris@0: 'app_version' => $this->version, Chris@0: 'token' => $response->headers->get('X-Debug-Token'), Chris@0: 'symfony_version' => Kernel::VERSION, Chris@0: 'symfony_state' => 'unknown', Chris@0: 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a', Chris@0: 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a', Chris@0: 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', Chris@0: 'php_version' => PHP_VERSION, Chris@14: 'php_architecture' => PHP_INT_SIZE * 8, Chris@14: 'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', Chris@14: 'php_timezone' => date_default_timezone_get(), Chris@17: 'xdebug_enabled' => \extension_loaded('xdebug'), Chris@17: 'apcu_enabled' => \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN), Chris@17: 'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN), Chris@17: 'bundles' => [], Chris@17: 'sapi_name' => \PHP_SAPI, Chris@17: ]; Chris@0: Chris@0: if (isset($this->kernel)) { Chris@0: foreach ($this->kernel->getBundles() as $name => $bundle) { Chris@14: $this->data['bundles'][$name] = $this->hasVarDumper ? new LinkStub($bundle->getPath()) : $bundle->getPath(); Chris@0: } Chris@0: Chris@0: $this->data['symfony_state'] = $this->determineSymfonyState(); Chris@14: $this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION); Chris@14: $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE); Chris@14: $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE); Chris@14: $this->data['symfony_eom'] = $eom->format('F Y'); Chris@14: $this->data['symfony_eol'] = $eol->format('F Y'); Chris@0: } Chris@14: Chris@14: if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) { Chris@14: $this->data['php_version'] = $matches[1]; Chris@14: $this->data['php_version_extra'] = $matches[2]; Chris@14: } Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function reset() Chris@14: { Chris@17: $this->data = []; Chris@14: } Chris@14: Chris@14: public function lateCollect() Chris@14: { Chris@14: $this->data = $this->cloneVar($this->data); Chris@0: } Chris@0: Chris@0: public function getApplicationName() Chris@0: { Chris@0: return $this->data['app_name']; Chris@0: } Chris@0: Chris@0: public function getApplicationVersion() Chris@0: { Chris@0: return $this->data['app_version']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the token. Chris@0: * Chris@0: * @return string The token Chris@0: */ Chris@0: public function getToken() Chris@0: { Chris@0: return $this->data['token']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the Symfony version. Chris@0: * Chris@0: * @return string The Symfony version Chris@0: */ Chris@0: public function getSymfonyVersion() Chris@0: { Chris@0: return $this->data['symfony_version']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the state of the current Symfony release. Chris@0: * Chris@0: * @return string One of: unknown, dev, stable, eom, eol Chris@0: */ Chris@0: public function getSymfonyState() Chris@0: { Chris@0: return $this->data['symfony_state']; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Returns the minor Symfony version used (without patch numbers of extra Chris@14: * suffix like "RC", "beta", etc.). Chris@14: * Chris@14: * @return string Chris@14: */ Chris@14: public function getSymfonyMinorVersion() Chris@14: { Chris@14: return $this->data['symfony_minor_version']; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the human redable date when this Symfony version ends its Chris@14: * maintenance period. Chris@14: * Chris@14: * @return string Chris@14: */ Chris@14: public function getSymfonyEom() Chris@14: { Chris@14: return $this->data['symfony_eom']; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the human redable date when this Symfony version reaches its Chris@14: * "end of life" and won't receive bugs or security fixes. Chris@14: * Chris@14: * @return string Chris@14: */ Chris@14: public function getSymfonyEol() Chris@14: { Chris@14: return $this->data['symfony_eol']; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Gets the PHP version. Chris@0: * Chris@0: * @return string The PHP version Chris@0: */ Chris@0: public function getPhpVersion() Chris@0: { Chris@0: return $this->data['php_version']; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Gets the PHP version extra part. Chris@14: * Chris@14: * @return string|null The extra part Chris@14: */ Chris@14: public function getPhpVersionExtra() Chris@14: { Chris@14: return isset($this->data['php_version_extra']) ? $this->data['php_version_extra'] : null; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return int The PHP architecture as number of bits (e.g. 32 or 64) Chris@14: */ Chris@14: public function getPhpArchitecture() Chris@14: { Chris@14: return $this->data['php_architecture']; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return string Chris@14: */ Chris@14: public function getPhpIntlLocale() Chris@14: { Chris@14: return $this->data['php_intl_locale']; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return string Chris@14: */ Chris@14: public function getPhpTimezone() Chris@14: { Chris@14: return $this->data['php_timezone']; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Gets the application name. Chris@0: * Chris@0: * @return string The application name Chris@0: */ Chris@0: public function getAppName() Chris@0: { Chris@0: return $this->data['name']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the environment. Chris@0: * Chris@0: * @return string The environment Chris@0: */ Chris@0: public function getEnv() Chris@0: { Chris@0: return $this->data['env']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns true if the debug is enabled. Chris@0: * Chris@0: * @return bool true if debug is enabled, false otherwise Chris@0: */ Chris@0: public function isDebug() Chris@0: { Chris@0: return $this->data['debug']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns true if the XDebug is enabled. Chris@0: * Chris@0: * @return bool true if XDebug is enabled, false otherwise Chris@0: */ Chris@0: public function hasXDebug() Chris@0: { Chris@0: return $this->data['xdebug_enabled']; Chris@0: } Chris@0: Chris@0: /** Chris@14: * Returns true if APCu is enabled. Chris@0: * Chris@14: * @return bool true if APCu is enabled, false otherwise Chris@0: */ Chris@14: public function hasApcu() Chris@0: { Chris@14: return $this->data['apcu_enabled']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns true if Zend OPcache is enabled. Chris@0: * Chris@0: * @return bool true if Zend OPcache is enabled, false otherwise Chris@0: */ Chris@0: public function hasZendOpcache() Chris@0: { Chris@0: return $this->data['zend_opcache_enabled']; Chris@0: } Chris@0: Chris@0: public function getBundles() Chris@0: { Chris@0: return $this->data['bundles']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the PHP SAPI name. Chris@0: * Chris@0: * @return string The environment Chris@0: */ Chris@0: public function getSapiName() Chris@0: { Chris@0: return $this->data['sapi_name']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return 'config'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tries to retrieve information about the current Symfony version. Chris@0: * Chris@0: * @return string One of: dev, stable, eom, eol Chris@0: */ Chris@0: private function determineSymfonyState() Chris@0: { Chris@0: $now = new \DateTime(); Chris@0: $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month'); Chris@0: $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month'); Chris@0: Chris@0: if ($now > $eol) { Chris@0: $versionState = 'eol'; Chris@0: } elseif ($now > $eom) { Chris@0: $versionState = 'eom'; Chris@0: } elseif ('' !== Kernel::EXTRA_VERSION) { Chris@0: $versionState = 'dev'; Chris@0: } else { Chris@0: $versionState = 'stable'; Chris@0: } Chris@0: Chris@0: return $versionState; Chris@0: } Chris@0: }