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