annotate vendor/symfony/http-kernel/DataCollector/ConfigDataCollector.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
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\HttpFoundation\Request;
Chris@0 15 use Symfony\Component\HttpFoundation\Response;
Chris@17 16 use Symfony\Component\HttpKernel\Kernel;
Chris@17 17 use Symfony\Component\HttpKernel\KernelInterface;
Chris@14 18 use Symfony\Component\VarDumper\Caster\LinkStub;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 22 */
Chris@14 23 class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
Chris@0 24 {
Chris@0 25 /**
Chris@0 26 * @var KernelInterface
Chris@0 27 */
Chris@0 28 private $kernel;
Chris@0 29 private $name;
Chris@0 30 private $version;
Chris@14 31 private $hasVarDumper;
Chris@0 32
Chris@0 33 /**
Chris@0 34 * @param string $name The name of the application using the web profiler
Chris@0 35 * @param string $version The version of the application using the web profiler
Chris@0 36 */
Chris@0 37 public function __construct($name = null, $version = null)
Chris@0 38 {
Chris@0 39 $this->name = $name;
Chris@0 40 $this->version = $version;
Chris@14 41 $this->hasVarDumper = class_exists(LinkStub::class);
Chris@0 42 }
Chris@0 43
Chris@0 44 /**
Chris@0 45 * Sets the Kernel associated with this Request.
Chris@0 46 */
Chris@0 47 public function setKernel(KernelInterface $kernel = null)
Chris@0 48 {
Chris@0 49 $this->kernel = $kernel;
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * {@inheritdoc}
Chris@0 54 */
Chris@0 55 public function collect(Request $request, Response $response, \Exception $exception = null)
Chris@0 56 {
Chris@17 57 $this->data = [
Chris@0 58 'app_name' => $this->name,
Chris@0 59 'app_version' => $this->version,
Chris@0 60 'token' => $response->headers->get('X-Debug-Token'),
Chris@0 61 'symfony_version' => Kernel::VERSION,
Chris@0 62 'symfony_state' => 'unknown',
Chris@0 63 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
Chris@0 64 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
Chris@0 65 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
Chris@0 66 'php_version' => PHP_VERSION,
Chris@14 67 'php_architecture' => PHP_INT_SIZE * 8,
Chris@14 68 'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
Chris@14 69 'php_timezone' => date_default_timezone_get(),
Chris@17 70 'xdebug_enabled' => \extension_loaded('xdebug'),
Chris@17 71 'apcu_enabled' => \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN),
Chris@17 72 'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN),
Chris@17 73 'bundles' => [],
Chris@17 74 'sapi_name' => \PHP_SAPI,
Chris@17 75 ];
Chris@0 76
Chris@0 77 if (isset($this->kernel)) {
Chris@0 78 foreach ($this->kernel->getBundles() as $name => $bundle) {
Chris@14 79 $this->data['bundles'][$name] = $this->hasVarDumper ? new LinkStub($bundle->getPath()) : $bundle->getPath();
Chris@0 80 }
Chris@0 81
Chris@0 82 $this->data['symfony_state'] = $this->determineSymfonyState();
Chris@14 83 $this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
Chris@14 84 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE);
Chris@14 85 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE);
Chris@14 86 $this->data['symfony_eom'] = $eom->format('F Y');
Chris@14 87 $this->data['symfony_eol'] = $eol->format('F Y');
Chris@0 88 }
Chris@14 89
Chris@14 90 if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
Chris@14 91 $this->data['php_version'] = $matches[1];
Chris@14 92 $this->data['php_version_extra'] = $matches[2];
Chris@14 93 }
Chris@14 94 }
Chris@14 95
Chris@14 96 /**
Chris@14 97 * {@inheritdoc}
Chris@14 98 */
Chris@14 99 public function reset()
Chris@14 100 {
Chris@17 101 $this->data = [];
Chris@14 102 }
Chris@14 103
Chris@14 104 public function lateCollect()
Chris@14 105 {
Chris@14 106 $this->data = $this->cloneVar($this->data);
Chris@0 107 }
Chris@0 108
Chris@0 109 public function getApplicationName()
Chris@0 110 {
Chris@0 111 return $this->data['app_name'];
Chris@0 112 }
Chris@0 113
Chris@0 114 public function getApplicationVersion()
Chris@0 115 {
Chris@0 116 return $this->data['app_version'];
Chris@0 117 }
Chris@0 118
Chris@0 119 /**
Chris@0 120 * Gets the token.
Chris@0 121 *
Chris@0 122 * @return string The token
Chris@0 123 */
Chris@0 124 public function getToken()
Chris@0 125 {
Chris@0 126 return $this->data['token'];
Chris@0 127 }
Chris@0 128
Chris@0 129 /**
Chris@0 130 * Gets the Symfony version.
Chris@0 131 *
Chris@0 132 * @return string The Symfony version
Chris@0 133 */
Chris@0 134 public function getSymfonyVersion()
Chris@0 135 {
Chris@0 136 return $this->data['symfony_version'];
Chris@0 137 }
Chris@0 138
Chris@0 139 /**
Chris@0 140 * Returns the state of the current Symfony release.
Chris@0 141 *
Chris@0 142 * @return string One of: unknown, dev, stable, eom, eol
Chris@0 143 */
Chris@0 144 public function getSymfonyState()
Chris@0 145 {
Chris@0 146 return $this->data['symfony_state'];
Chris@0 147 }
Chris@0 148
Chris@0 149 /**
Chris@14 150 * Returns the minor Symfony version used (without patch numbers of extra
Chris@14 151 * suffix like "RC", "beta", etc.).
Chris@14 152 *
Chris@14 153 * @return string
Chris@14 154 */
Chris@14 155 public function getSymfonyMinorVersion()
Chris@14 156 {
Chris@14 157 return $this->data['symfony_minor_version'];
Chris@14 158 }
Chris@14 159
Chris@14 160 /**
Chris@14 161 * Returns the human redable date when this Symfony version ends its
Chris@14 162 * maintenance period.
Chris@14 163 *
Chris@14 164 * @return string
Chris@14 165 */
Chris@14 166 public function getSymfonyEom()
Chris@14 167 {
Chris@14 168 return $this->data['symfony_eom'];
Chris@14 169 }
Chris@14 170
Chris@14 171 /**
Chris@14 172 * Returns the human redable date when this Symfony version reaches its
Chris@14 173 * "end of life" and won't receive bugs or security fixes.
Chris@14 174 *
Chris@14 175 * @return string
Chris@14 176 */
Chris@14 177 public function getSymfonyEol()
Chris@14 178 {
Chris@14 179 return $this->data['symfony_eol'];
Chris@14 180 }
Chris@14 181
Chris@14 182 /**
Chris@0 183 * Gets the PHP version.
Chris@0 184 *
Chris@0 185 * @return string The PHP version
Chris@0 186 */
Chris@0 187 public function getPhpVersion()
Chris@0 188 {
Chris@0 189 return $this->data['php_version'];
Chris@0 190 }
Chris@0 191
Chris@0 192 /**
Chris@14 193 * Gets the PHP version extra part.
Chris@14 194 *
Chris@14 195 * @return string|null The extra part
Chris@14 196 */
Chris@14 197 public function getPhpVersionExtra()
Chris@14 198 {
Chris@14 199 return isset($this->data['php_version_extra']) ? $this->data['php_version_extra'] : null;
Chris@14 200 }
Chris@14 201
Chris@14 202 /**
Chris@14 203 * @return int The PHP architecture as number of bits (e.g. 32 or 64)
Chris@14 204 */
Chris@14 205 public function getPhpArchitecture()
Chris@14 206 {
Chris@14 207 return $this->data['php_architecture'];
Chris@14 208 }
Chris@14 209
Chris@14 210 /**
Chris@14 211 * @return string
Chris@14 212 */
Chris@14 213 public function getPhpIntlLocale()
Chris@14 214 {
Chris@14 215 return $this->data['php_intl_locale'];
Chris@14 216 }
Chris@14 217
Chris@14 218 /**
Chris@14 219 * @return string
Chris@14 220 */
Chris@14 221 public function getPhpTimezone()
Chris@14 222 {
Chris@14 223 return $this->data['php_timezone'];
Chris@14 224 }
Chris@14 225
Chris@14 226 /**
Chris@0 227 * Gets the application name.
Chris@0 228 *
Chris@0 229 * @return string The application name
Chris@0 230 */
Chris@0 231 public function getAppName()
Chris@0 232 {
Chris@0 233 return $this->data['name'];
Chris@0 234 }
Chris@0 235
Chris@0 236 /**
Chris@0 237 * Gets the environment.
Chris@0 238 *
Chris@0 239 * @return string The environment
Chris@0 240 */
Chris@0 241 public function getEnv()
Chris@0 242 {
Chris@0 243 return $this->data['env'];
Chris@0 244 }
Chris@0 245
Chris@0 246 /**
Chris@0 247 * Returns true if the debug is enabled.
Chris@0 248 *
Chris@0 249 * @return bool true if debug is enabled, false otherwise
Chris@0 250 */
Chris@0 251 public function isDebug()
Chris@0 252 {
Chris@0 253 return $this->data['debug'];
Chris@0 254 }
Chris@0 255
Chris@0 256 /**
Chris@0 257 * Returns true if the XDebug is enabled.
Chris@0 258 *
Chris@0 259 * @return bool true if XDebug is enabled, false otherwise
Chris@0 260 */
Chris@0 261 public function hasXDebug()
Chris@0 262 {
Chris@0 263 return $this->data['xdebug_enabled'];
Chris@0 264 }
Chris@0 265
Chris@0 266 /**
Chris@14 267 * Returns true if APCu is enabled.
Chris@0 268 *
Chris@14 269 * @return bool true if APCu is enabled, false otherwise
Chris@0 270 */
Chris@14 271 public function hasApcu()
Chris@0 272 {
Chris@14 273 return $this->data['apcu_enabled'];
Chris@0 274 }
Chris@0 275
Chris@0 276 /**
Chris@0 277 * Returns true if Zend OPcache is enabled.
Chris@0 278 *
Chris@0 279 * @return bool true if Zend OPcache is enabled, false otherwise
Chris@0 280 */
Chris@0 281 public function hasZendOpcache()
Chris@0 282 {
Chris@0 283 return $this->data['zend_opcache_enabled'];
Chris@0 284 }
Chris@0 285
Chris@0 286 public function getBundles()
Chris@0 287 {
Chris@0 288 return $this->data['bundles'];
Chris@0 289 }
Chris@0 290
Chris@0 291 /**
Chris@0 292 * Gets the PHP SAPI name.
Chris@0 293 *
Chris@0 294 * @return string The environment
Chris@0 295 */
Chris@0 296 public function getSapiName()
Chris@0 297 {
Chris@0 298 return $this->data['sapi_name'];
Chris@0 299 }
Chris@0 300
Chris@0 301 /**
Chris@0 302 * {@inheritdoc}
Chris@0 303 */
Chris@0 304 public function getName()
Chris@0 305 {
Chris@0 306 return 'config';
Chris@0 307 }
Chris@0 308
Chris@0 309 /**
Chris@0 310 * Tries to retrieve information about the current Symfony version.
Chris@0 311 *
Chris@0 312 * @return string One of: dev, stable, eom, eol
Chris@0 313 */
Chris@0 314 private function determineSymfonyState()
Chris@0 315 {
Chris@0 316 $now = new \DateTime();
Chris@0 317 $eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
Chris@0 318 $eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
Chris@0 319
Chris@0 320 if ($now > $eol) {
Chris@0 321 $versionState = 'eol';
Chris@0 322 } elseif ($now > $eom) {
Chris@0 323 $versionState = 'eom';
Chris@0 324 } elseif ('' !== Kernel::EXTRA_VERSION) {
Chris@0 325 $versionState = 'dev';
Chris@0 326 } else {
Chris@0 327 $versionState = 'stable';
Chris@0 328 }
Chris@0 329
Chris@0 330 return $versionState;
Chris@0 331 }
Chris@0 332 }