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;
20 * ConfigDataCollector.
22 * @author Fabien Potencier <fabien@symfony.com>
24 class ConfigDataCollector extends DataCollector
27 * @var KernelInterface
36 * @param string $name The name of the application using the web profiler
37 * @param string $version The version of the application using the web profiler
39 public function __construct($name = null, $version = null)
42 $this->version = $version;
46 * Sets the Kernel associated with this Request.
48 * @param KernelInterface $kernel A KernelInterface instance
50 public function setKernel(KernelInterface $kernel = null)
52 $this->kernel = $kernel;
58 public function collect(Request $request, Response $response, \Exception $exception = null)
61 'app_name' => $this->name,
62 'app_version' => $this->version,
63 'token' => $response->headers->get('X-Debug-Token'),
64 'symfony_version' => Kernel::VERSION,
65 'symfony_state' => 'unknown',
66 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
67 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
68 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
69 'php_version' => PHP_VERSION,
70 'xdebug_enabled' => extension_loaded('xdebug'),
71 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
72 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
73 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
74 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
75 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
77 'sapi_name' => PHP_SAPI,
80 if (isset($this->kernel)) {
81 foreach ($this->kernel->getBundles() as $name => $bundle) {
82 $this->data['bundles'][$name] = $bundle->getPath();
85 $this->data['symfony_state'] = $this->determineSymfonyState();
89 public function getApplicationName()
91 return $this->data['app_name'];
94 public function getApplicationVersion()
96 return $this->data['app_version'];
102 * @return string The token
104 public function getToken()
106 return $this->data['token'];
110 * Gets the Symfony version.
112 * @return string The Symfony version
114 public function getSymfonyVersion()
116 return $this->data['symfony_version'];
120 * Returns the state of the current Symfony release.
122 * @return string One of: unknown, dev, stable, eom, eol
124 public function getSymfonyState()
126 return $this->data['symfony_state'];
130 * Gets the PHP version.
132 * @return string The PHP version
134 public function getPhpVersion()
136 return $this->data['php_version'];
140 * Gets the application name.
142 * @return string The application name
144 public function getAppName()
146 return $this->data['name'];
150 * Gets the environment.
152 * @return string The environment
154 public function getEnv()
156 return $this->data['env'];
160 * Returns true if the debug is enabled.
162 * @return bool true if debug is enabled, false otherwise
164 public function isDebug()
166 return $this->data['debug'];
170 * Returns true if the XDebug is enabled.
172 * @return bool true if XDebug is enabled, false otherwise
174 public function hasXDebug()
176 return $this->data['xdebug_enabled'];
180 * Returns true if EAccelerator is enabled.
182 * @return bool true if EAccelerator is enabled, false otherwise
184 public function hasEAccelerator()
186 return $this->data['eaccel_enabled'];
190 * Returns true if APC is enabled.
192 * @return bool true if APC is enabled, false otherwise
194 public function hasApc()
196 return $this->data['apc_enabled'];
200 * Returns true if Zend OPcache is enabled.
202 * @return bool true if Zend OPcache is enabled, false otherwise
204 public function hasZendOpcache()
206 return $this->data['zend_opcache_enabled'];
210 * Returns true if XCache is enabled.
212 * @return bool true if XCache is enabled, false otherwise
214 public function hasXCache()
216 return $this->data['xcache_enabled'];
220 * Returns true if WinCache is enabled.
222 * @return bool true if WinCache is enabled, false otherwise
224 public function hasWinCache()
226 return $this->data['wincache_enabled'];
230 * Returns true if any accelerator is enabled.
232 * @return bool true if any accelerator is enabled, false otherwise
234 public function hasAccelerator()
236 return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
239 public function getBundles()
241 return $this->data['bundles'];
245 * Gets the PHP SAPI name.
247 * @return string The environment
249 public function getSapiName()
251 return $this->data['sapi_name'];
257 public function getName()
263 * Tries to retrieve information about the current Symfony version.
265 * @return string One of: dev, stable, eom, eol
267 private function determineSymfonyState()
269 $now = new \DateTime();
270 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
271 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
274 $versionState = 'eol';
275 } elseif ($now > $eom) {
276 $versionState = 'eom';
277 } elseif ('' !== Kernel::EXTRA_VERSION) {
278 $versionState = 'dev';
280 $versionState = 'stable';
283 return $versionState;