comparison vendor/symfony/http-kernel/DataCollector/ConfigDataCollector.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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
33 /**
34 * Constructor.
35 *
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
38 */
39 public function __construct($name = null, $version = null)
40 {
41 $this->name = $name;
42 $this->version = $version;
43 }
44
45 /**
46 * Sets the Kernel associated with this Request.
47 *
48 * @param KernelInterface $kernel A KernelInterface instance
49 */
50 public function setKernel(KernelInterface $kernel = null)
51 {
52 $this->kernel = $kernel;
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function collect(Request $request, Response $response, \Exception $exception = null)
59 {
60 $this->data = array(
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'),
76 'bundles' => array(),
77 'sapi_name' => PHP_SAPI,
78 );
79
80 if (isset($this->kernel)) {
81 foreach ($this->kernel->getBundles() as $name => $bundle) {
82 $this->data['bundles'][$name] = $bundle->getPath();
83 }
84
85 $this->data['symfony_state'] = $this->determineSymfonyState();
86 }
87 }
88
89 public function getApplicationName()
90 {
91 return $this->data['app_name'];
92 }
93
94 public function getApplicationVersion()
95 {
96 return $this->data['app_version'];
97 }
98
99 /**
100 * Gets the token.
101 *
102 * @return string The token
103 */
104 public function getToken()
105 {
106 return $this->data['token'];
107 }
108
109 /**
110 * Gets the Symfony version.
111 *
112 * @return string The Symfony version
113 */
114 public function getSymfonyVersion()
115 {
116 return $this->data['symfony_version'];
117 }
118
119 /**
120 * Returns the state of the current Symfony release.
121 *
122 * @return string One of: unknown, dev, stable, eom, eol
123 */
124 public function getSymfonyState()
125 {
126 return $this->data['symfony_state'];
127 }
128
129 /**
130 * Gets the PHP version.
131 *
132 * @return string The PHP version
133 */
134 public function getPhpVersion()
135 {
136 return $this->data['php_version'];
137 }
138
139 /**
140 * Gets the application name.
141 *
142 * @return string The application name
143 */
144 public function getAppName()
145 {
146 return $this->data['name'];
147 }
148
149 /**
150 * Gets the environment.
151 *
152 * @return string The environment
153 */
154 public function getEnv()
155 {
156 return $this->data['env'];
157 }
158
159 /**
160 * Returns true if the debug is enabled.
161 *
162 * @return bool true if debug is enabled, false otherwise
163 */
164 public function isDebug()
165 {
166 return $this->data['debug'];
167 }
168
169 /**
170 * Returns true if the XDebug is enabled.
171 *
172 * @return bool true if XDebug is enabled, false otherwise
173 */
174 public function hasXDebug()
175 {
176 return $this->data['xdebug_enabled'];
177 }
178
179 /**
180 * Returns true if EAccelerator is enabled.
181 *
182 * @return bool true if EAccelerator is enabled, false otherwise
183 */
184 public function hasEAccelerator()
185 {
186 return $this->data['eaccel_enabled'];
187 }
188
189 /**
190 * Returns true if APC is enabled.
191 *
192 * @return bool true if APC is enabled, false otherwise
193 */
194 public function hasApc()
195 {
196 return $this->data['apc_enabled'];
197 }
198
199 /**
200 * Returns true if Zend OPcache is enabled.
201 *
202 * @return bool true if Zend OPcache is enabled, false otherwise
203 */
204 public function hasZendOpcache()
205 {
206 return $this->data['zend_opcache_enabled'];
207 }
208
209 /**
210 * Returns true if XCache is enabled.
211 *
212 * @return bool true if XCache is enabled, false otherwise
213 */
214 public function hasXCache()
215 {
216 return $this->data['xcache_enabled'];
217 }
218
219 /**
220 * Returns true if WinCache is enabled.
221 *
222 * @return bool true if WinCache is enabled, false otherwise
223 */
224 public function hasWinCache()
225 {
226 return $this->data['wincache_enabled'];
227 }
228
229 /**
230 * Returns true if any accelerator is enabled.
231 *
232 * @return bool true if any accelerator is enabled, false otherwise
233 */
234 public function hasAccelerator()
235 {
236 return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
237 }
238
239 public function getBundles()
240 {
241 return $this->data['bundles'];
242 }
243
244 /**
245 * Gets the PHP SAPI name.
246 *
247 * @return string The environment
248 */
249 public function getSapiName()
250 {
251 return $this->data['sapi_name'];
252 }
253
254 /**
255 * {@inheritdoc}
256 */
257 public function getName()
258 {
259 return 'config';
260 }
261
262 /**
263 * Tries to retrieve information about the current Symfony version.
264 *
265 * @return string One of: dev, stable, eom, eol
266 */
267 private function determineSymfonyState()
268 {
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');
272
273 if ($now > $eol) {
274 $versionState = 'eol';
275 } elseif ($now > $eom) {
276 $versionState = 'eom';
277 } elseif ('' !== Kernel::EXTRA_VERSION) {
278 $versionState = 'dev';
279 } else {
280 $versionState = 'stable';
281 }
282
283 return $versionState;
284 }
285 }