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
32 private $cacheVersionInfo = true;
37 * @param string $name The name of the application using the web profiler
38 * @param string $version The version of the application using the web profiler
40 public function __construct($name = null, $version = null)
43 $this->version = $version;
47 * Sets the Kernel associated with this Request.
49 * @param KernelInterface $kernel A KernelInterface instance
51 public function setKernel(KernelInterface $kernel = null)
53 $this->kernel = $kernel;
59 public function collect(Request $request, Response $response, \Exception $exception = null)
62 'app_name' => $this->name,
63 'app_version' => $this->version,
64 'token' => $response->headers->get('X-Debug-Token'),
65 'symfony_version' => Kernel::VERSION,
66 'symfony_state' => 'unknown',
67 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
68 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
69 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
70 'php_version' => PHP_VERSION,
71 'xdebug_enabled' => extension_loaded('xdebug'),
72 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
73 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'),
74 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'),
75 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'),
76 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'),
78 'sapi_name' => PHP_SAPI,
81 if (isset($this->kernel)) {
82 foreach ($this->kernel->getBundles() as $name => $bundle) {
83 $this->data['bundles'][$name] = $bundle->getPath();
86 $this->data['symfony_state'] = $this->determineSymfonyState();
90 public function getApplicationName()
92 return $this->data['app_name'];
95 public function getApplicationVersion()
97 return $this->data['app_version'];
103 * @return string The token
105 public function getToken()
107 return $this->data['token'];
111 * Gets the Symfony version.
113 * @return string The Symfony version
115 public function getSymfonyVersion()
117 return $this->data['symfony_version'];
121 * Returns the state of the current Symfony release.
123 * @return string One of: unknown, dev, stable, eom, eol
125 public function getSymfonyState()
127 return $this->data['symfony_state'];
130 public function setCacheVersionInfo($cacheVersionInfo)
132 $this->cacheVersionInfo = $cacheVersionInfo;
136 * Gets the PHP version.
138 * @return string The PHP version
140 public function getPhpVersion()
142 return $this->data['php_version'];
146 * Gets the application name.
148 * @return string The application name
150 public function getAppName()
152 return $this->data['name'];
156 * Gets the environment.
158 * @return string The environment
160 public function getEnv()
162 return $this->data['env'];
166 * Returns true if the debug is enabled.
168 * @return bool true if debug is enabled, false otherwise
170 public function isDebug()
172 return $this->data['debug'];
176 * Returns true if the XDebug is enabled.
178 * @return bool true if XDebug is enabled, false otherwise
180 public function hasXDebug()
182 return $this->data['xdebug_enabled'];
186 * Returns true if EAccelerator is enabled.
188 * @return bool true if EAccelerator is enabled, false otherwise
190 public function hasEAccelerator()
192 return $this->data['eaccel_enabled'];
196 * Returns true if APC is enabled.
198 * @return bool true if APC is enabled, false otherwise
200 public function hasApc()
202 return $this->data['apc_enabled'];
206 * Returns true if Zend OPcache is enabled.
208 * @return bool true if Zend OPcache is enabled, false otherwise
210 public function hasZendOpcache()
212 return $this->data['zend_opcache_enabled'];
216 * Returns true if XCache is enabled.
218 * @return bool true if XCache is enabled, false otherwise
220 public function hasXCache()
222 return $this->data['xcache_enabled'];
226 * Returns true if WinCache is enabled.
228 * @return bool true if WinCache is enabled, false otherwise
230 public function hasWinCache()
232 return $this->data['wincache_enabled'];
236 * Returns true if any accelerator is enabled.
238 * @return bool true if any accelerator is enabled, false otherwise
240 public function hasAccelerator()
242 return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
245 public function getBundles()
247 return $this->data['bundles'];
251 * Gets the PHP SAPI name.
253 * @return string The environment
255 public function getSapiName()
257 return $this->data['sapi_name'];
263 public function getName()
269 * Tries to retrieve information about the current Symfony version.
271 * @return string One of: dev, stable, eom, eol
273 private function determineSymfonyState()
275 $now = new \DateTime();
276 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
277 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
280 $versionState = 'eol';
281 } elseif ($now > $eom) {
282 $versionState = 'eom';
283 } elseif ('' !== Kernel::EXTRA_VERSION) {
284 $versionState = 'dev';
286 $versionState = 'stable';
289 return $versionState;