4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DataCollector;
14 use Symfony\Component\HttpKernel\KernelInterface;
15 use Symfony\Component\HttpKernel\Kernel;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18 use Symfony\Component\VarDumper\Caster\LinkStub;
21 * @author Fabien Potencier <fabien@symfony.com>
23 class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
26 * @var KernelInterface
31 private $hasVarDumper;
34 * @param string $name The name of the application using the web profiler
35 * @param string $version The version of the application using the web profiler
37 public function __construct($name = null, $version = null)
40 $this->version = $version;
41 $this->hasVarDumper = class_exists(LinkStub::class);
45 * Sets the Kernel associated with this Request.
47 public function setKernel(KernelInterface $kernel = null)
49 $this->kernel = $kernel;
55 public function collect(Request $request, Response $response, \Exception $exception = null)
58 'app_name' => $this->name,
59 'app_version' => $this->version,
60 'token' => $response->headers->get('X-Debug-Token'),
61 'symfony_version' => Kernel::VERSION,
62 'symfony_state' => 'unknown',
63 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
64 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
65 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
66 'php_version' => PHP_VERSION,
67 'php_architecture' => PHP_INT_SIZE * 8,
68 'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
69 'php_timezone' => date_default_timezone_get(),
70 'xdebug_enabled' => extension_loaded('xdebug'),
71 'apcu_enabled' => extension_loaded('apcu') && ini_get('apc.enabled'),
72 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
74 'sapi_name' => PHP_SAPI,
77 if (isset($this->kernel)) {
78 foreach ($this->kernel->getBundles() as $name => $bundle) {
79 $this->data['bundles'][$name] = $this->hasVarDumper ? new LinkStub($bundle->getPath()) : $bundle->getPath();
82 $this->data['symfony_state'] = $this->determineSymfonyState();
83 $this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
84 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE);
85 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE);
86 $this->data['symfony_eom'] = $eom->format('F Y');
87 $this->data['symfony_eol'] = $eol->format('F Y');
90 if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
91 $this->data['php_version'] = $matches[1];
92 $this->data['php_version_extra'] = $matches[2];
99 public function reset()
101 $this->data = array();
104 public function lateCollect()
106 $this->data = $this->cloneVar($this->data);
109 public function getApplicationName()
111 return $this->data['app_name'];
114 public function getApplicationVersion()
116 return $this->data['app_version'];
122 * @return string The token
124 public function getToken()
126 return $this->data['token'];
130 * Gets the Symfony version.
132 * @return string The Symfony version
134 public function getSymfonyVersion()
136 return $this->data['symfony_version'];
140 * Returns the state of the current Symfony release.
142 * @return string One of: unknown, dev, stable, eom, eol
144 public function getSymfonyState()
146 return $this->data['symfony_state'];
150 * Returns the minor Symfony version used (without patch numbers of extra
151 * suffix like "RC", "beta", etc.).
155 public function getSymfonyMinorVersion()
157 return $this->data['symfony_minor_version'];
161 * Returns the human redable date when this Symfony version ends its
162 * maintenance period.
166 public function getSymfonyEom()
168 return $this->data['symfony_eom'];
172 * Returns the human redable date when this Symfony version reaches its
173 * "end of life" and won't receive bugs or security fixes.
177 public function getSymfonyEol()
179 return $this->data['symfony_eol'];
183 * Gets the PHP version.
185 * @return string The PHP version
187 public function getPhpVersion()
189 return $this->data['php_version'];
193 * Gets the PHP version extra part.
195 * @return string|null The extra part
197 public function getPhpVersionExtra()
199 return isset($this->data['php_version_extra']) ? $this->data['php_version_extra'] : null;
203 * @return int The PHP architecture as number of bits (e.g. 32 or 64)
205 public function getPhpArchitecture()
207 return $this->data['php_architecture'];
213 public function getPhpIntlLocale()
215 return $this->data['php_intl_locale'];
221 public function getPhpTimezone()
223 return $this->data['php_timezone'];
227 * Gets the application name.
229 * @return string The application name
231 public function getAppName()
233 return $this->data['name'];
237 * Gets the environment.
239 * @return string The environment
241 public function getEnv()
243 return $this->data['env'];
247 * Returns true if the debug is enabled.
249 * @return bool true if debug is enabled, false otherwise
251 public function isDebug()
253 return $this->data['debug'];
257 * Returns true if the XDebug is enabled.
259 * @return bool true if XDebug is enabled, false otherwise
261 public function hasXDebug()
263 return $this->data['xdebug_enabled'];
267 * Returns true if APCu is enabled.
269 * @return bool true if APCu is enabled, false otherwise
271 public function hasApcu()
273 return $this->data['apcu_enabled'];
277 * Returns true if Zend OPcache is enabled.
279 * @return bool true if Zend OPcache is enabled, false otherwise
281 public function hasZendOpcache()
283 return $this->data['zend_opcache_enabled'];
286 public function getBundles()
288 return $this->data['bundles'];
292 * Gets the PHP SAPI name.
294 * @return string The environment
296 public function getSapiName()
298 return $this->data['sapi_name'];
304 public function getName()
310 * Tries to retrieve information about the current Symfony version.
312 * @return string One of: dev, stable, eom, eol
314 private function determineSymfonyState()
316 $now = new \DateTime();
317 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
318 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
321 $versionState = 'eol';
322 } elseif ($now > $eom) {
323 $versionState = 'eom';
324 } elseif ('' !== Kernel::EXTRA_VERSION) {
325 $versionState = 'dev';
327 $versionState = 'stable';
330 return $versionState;