Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-kernel / DataCollector / ConfigDataCollector.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\DataCollector;
13
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
19 /**
20  * ConfigDataCollector.
21  *
22  * @author Fabien Potencier <fabien@symfony.com>
23  */
24 class ConfigDataCollector extends DataCollector
25 {
26     /**
27      * @var KernelInterface
28      */
29     private $kernel;
30     private $name;
31     private $version;
32     private $cacheVersionInfo = true;
33
34     /**
35      * Constructor.
36      *
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
39      */
40     public function __construct($name = null, $version = null)
41     {
42         $this->name = $name;
43         $this->version = $version;
44     }
45
46     /**
47      * Sets the Kernel associated with this Request.
48      *
49      * @param KernelInterface $kernel A KernelInterface instance
50      */
51     public function setKernel(KernelInterface $kernel = null)
52     {
53         $this->kernel = $kernel;
54     }
55
56     /**
57      * {@inheritdoc}
58      */
59     public function collect(Request $request, Response $response, \Exception $exception = null)
60     {
61         $this->data = array(
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'),
77             'bundles' => array(),
78             'sapi_name' => PHP_SAPI,
79         );
80
81         if (isset($this->kernel)) {
82             foreach ($this->kernel->getBundles() as $name => $bundle) {
83                 $this->data['bundles'][$name] = $bundle->getPath();
84             }
85
86             $this->data['symfony_state'] = $this->determineSymfonyState();
87         }
88     }
89
90     public function getApplicationName()
91     {
92         return $this->data['app_name'];
93     }
94
95     public function getApplicationVersion()
96     {
97         return $this->data['app_version'];
98     }
99
100     /**
101      * Gets the token.
102      *
103      * @return string The token
104      */
105     public function getToken()
106     {
107         return $this->data['token'];
108     }
109
110     /**
111      * Gets the Symfony version.
112      *
113      * @return string The Symfony version
114      */
115     public function getSymfonyVersion()
116     {
117         return $this->data['symfony_version'];
118     }
119
120     /**
121      * Returns the state of the current Symfony release.
122      *
123      * @return string One of: unknown, dev, stable, eom, eol
124      */
125     public function getSymfonyState()
126     {
127         return $this->data['symfony_state'];
128     }
129
130     public function setCacheVersionInfo($cacheVersionInfo)
131     {
132         $this->cacheVersionInfo = $cacheVersionInfo;
133     }
134
135     /**
136      * Gets the PHP version.
137      *
138      * @return string The PHP version
139      */
140     public function getPhpVersion()
141     {
142         return $this->data['php_version'];
143     }
144
145     /**
146      * Gets the application name.
147      *
148      * @return string The application name
149      */
150     public function getAppName()
151     {
152         return $this->data['name'];
153     }
154
155     /**
156      * Gets the environment.
157      *
158      * @return string The environment
159      */
160     public function getEnv()
161     {
162         return $this->data['env'];
163     }
164
165     /**
166      * Returns true if the debug is enabled.
167      *
168      * @return bool true if debug is enabled, false otherwise
169      */
170     public function isDebug()
171     {
172         return $this->data['debug'];
173     }
174
175     /**
176      * Returns true if the XDebug is enabled.
177      *
178      * @return bool true if XDebug is enabled, false otherwise
179      */
180     public function hasXDebug()
181     {
182         return $this->data['xdebug_enabled'];
183     }
184
185     /**
186      * Returns true if EAccelerator is enabled.
187      *
188      * @return bool true if EAccelerator is enabled, false otherwise
189      */
190     public function hasEAccelerator()
191     {
192         return $this->data['eaccel_enabled'];
193     }
194
195     /**
196      * Returns true if APC is enabled.
197      *
198      * @return bool true if APC is enabled, false otherwise
199      */
200     public function hasApc()
201     {
202         return $this->data['apc_enabled'];
203     }
204
205     /**
206      * Returns true if Zend OPcache is enabled.
207      *
208      * @return bool true if Zend OPcache is enabled, false otherwise
209      */
210     public function hasZendOpcache()
211     {
212         return $this->data['zend_opcache_enabled'];
213     }
214
215     /**
216      * Returns true if XCache is enabled.
217      *
218      * @return bool true if XCache is enabled, false otherwise
219      */
220     public function hasXCache()
221     {
222         return $this->data['xcache_enabled'];
223     }
224
225     /**
226      * Returns true if WinCache is enabled.
227      *
228      * @return bool true if WinCache is enabled, false otherwise
229      */
230     public function hasWinCache()
231     {
232         return $this->data['wincache_enabled'];
233     }
234
235     /**
236      * Returns true if any accelerator is enabled.
237      *
238      * @return bool true if any accelerator is enabled, false otherwise
239      */
240     public function hasAccelerator()
241     {
242         return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
243     }
244
245     public function getBundles()
246     {
247         return $this->data['bundles'];
248     }
249
250     /**
251      * Gets the PHP SAPI name.
252      *
253      * @return string The environment
254      */
255     public function getSapiName()
256     {
257         return $this->data['sapi_name'];
258     }
259
260     /**
261      * {@inheritdoc}
262      */
263     public function getName()
264     {
265         return 'config';
266     }
267
268     /**
269      * Tries to retrieve information about the current Symfony version.
270      *
271      * @return string One of: dev, stable, eom, eol
272      */
273     private function determineSymfonyState()
274     {
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');
278
279         if ($now > $eol) {
280             $versionState = 'eol';
281         } elseif ($now > $eom) {
282             $versionState = 'eom';
283         } elseif ('' !== Kernel::EXTRA_VERSION) {
284             $versionState = 'dev';
285         } else {
286             $versionState = 'stable';
287         }
288
289         return $versionState;
290     }
291 }