| 148 |
lars |
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\HttpFoundation\Request;
|
|
|
15 |
use Symfony\Component\HttpFoundation\Response;
|
|
|
16 |
use Symfony\Component\HttpKernel\Kernel;
|
|
|
17 |
use Symfony\Component\HttpKernel\KernelInterface;
|
|
|
18 |
use Symfony\Component\VarDumper\Caster\ClassStub;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
22 |
*
|
|
|
23 |
* @final
|
|
|
24 |
*/
|
|
|
25 |
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
|
|
|
26 |
{
|
|
|
27 |
private KernelInterface $kernel;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Sets the Kernel associated with this Request.
|
|
|
31 |
*/
|
|
|
32 |
public function setKernel(KernelInterface $kernel = null)
|
|
|
33 |
{
|
|
|
34 |
if (1 > \func_num_args()) {
|
|
|
35 |
trigger_deprecation('symfony/http-kernel', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
$this->kernel = $kernel;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public function collect(Request $request, Response $response, \Throwable $exception = null)
|
|
|
42 |
{
|
|
|
43 |
$eom = \DateTimeImmutable::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
|
|
|
44 |
$eol = \DateTimeImmutable::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
|
|
|
45 |
|
|
|
46 |
$this->data = [
|
|
|
47 |
'token' => $response->headers->get('X-Debug-Token'),
|
|
|
48 |
'symfony_version' => Kernel::VERSION,
|
|
|
49 |
'symfony_minor_version' => sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION),
|
|
|
50 |
'symfony_lts' => 4 === Kernel::MINOR_VERSION,
|
|
|
51 |
'symfony_state' => $this->determineSymfonyState(),
|
|
|
52 |
'symfony_eom' => $eom->format('F Y'),
|
|
|
53 |
'symfony_eol' => $eol->format('F Y'),
|
|
|
54 |
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
|
|
|
55 |
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
|
|
|
56 |
'php_version' => \PHP_VERSION,
|
|
|
57 |
'php_architecture' => \PHP_INT_SIZE * 8,
|
|
|
58 |
'php_intl_locale' => class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
|
|
|
59 |
'php_timezone' => date_default_timezone_get(),
|
|
|
60 |
'xdebug_enabled' => \extension_loaded('xdebug'),
|
|
|
61 |
'apcu_enabled' => \extension_loaded('apcu') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL),
|
|
|
62 |
'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL),
|
|
|
63 |
'bundles' => [],
|
|
|
64 |
'sapi_name' => \PHP_SAPI,
|
|
|
65 |
];
|
|
|
66 |
|
|
|
67 |
if (isset($this->kernel)) {
|
|
|
68 |
foreach ($this->kernel->getBundles() as $name => $bundle) {
|
|
|
69 |
$this->data['bundles'][$name] = new ClassStub($bundle::class);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
|
|
|
74 |
$this->data['php_version'] = $matches[1];
|
|
|
75 |
$this->data['php_version_extra'] = $matches[2];
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public function reset()
|
|
|
80 |
{
|
|
|
81 |
$this->data = [];
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public function lateCollect()
|
|
|
85 |
{
|
|
|
86 |
$this->data = $this->cloneVar($this->data);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Gets the token.
|
|
|
91 |
*/
|
|
|
92 |
public function getToken(): ?string
|
|
|
93 |
{
|
|
|
94 |
return $this->data['token'];
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Gets the Symfony version.
|
|
|
99 |
*/
|
|
|
100 |
public function getSymfonyVersion(): string
|
|
|
101 |
{
|
|
|
102 |
return $this->data['symfony_version'];
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Returns the state of the current Symfony release
|
|
|
107 |
* as one of: unknown, dev, stable, eom, eol.
|
|
|
108 |
*/
|
|
|
109 |
public function getSymfonyState(): string
|
|
|
110 |
{
|
|
|
111 |
return $this->data['symfony_state'];
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Returns the minor Symfony version used (without patch numbers of extra
|
|
|
116 |
* suffix like "RC", "beta", etc.).
|
|
|
117 |
*/
|
|
|
118 |
public function getSymfonyMinorVersion(): string
|
|
|
119 |
{
|
|
|
120 |
return $this->data['symfony_minor_version'];
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public function isSymfonyLts(): bool
|
|
|
124 |
{
|
|
|
125 |
return $this->data['symfony_lts'];
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Returns the human readable date when this Symfony version ends its
|
|
|
130 |
* maintenance period.
|
|
|
131 |
*/
|
|
|
132 |
public function getSymfonyEom(): string
|
|
|
133 |
{
|
|
|
134 |
return $this->data['symfony_eom'];
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Returns the human readable date when this Symfony version reaches its
|
|
|
139 |
* "end of life" and won't receive bugs or security fixes.
|
|
|
140 |
*/
|
|
|
141 |
public function getSymfonyEol(): string
|
|
|
142 |
{
|
|
|
143 |
return $this->data['symfony_eol'];
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Gets the PHP version.
|
|
|
148 |
*/
|
|
|
149 |
public function getPhpVersion(): string
|
|
|
150 |
{
|
|
|
151 |
return $this->data['php_version'];
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Gets the PHP version extra part.
|
|
|
156 |
*/
|
|
|
157 |
public function getPhpVersionExtra(): ?string
|
|
|
158 |
{
|
|
|
159 |
return $this->data['php_version_extra'] ?? null;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
public function getPhpArchitecture(): int
|
|
|
163 |
{
|
|
|
164 |
return $this->data['php_architecture'];
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
public function getPhpIntlLocale(): string
|
|
|
168 |
{
|
|
|
169 |
return $this->data['php_intl_locale'];
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
public function getPhpTimezone(): string
|
|
|
173 |
{
|
|
|
174 |
return $this->data['php_timezone'];
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
/**
|
|
|
178 |
* Gets the environment.
|
|
|
179 |
*/
|
|
|
180 |
public function getEnv(): string
|
|
|
181 |
{
|
|
|
182 |
return $this->data['env'];
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
* Returns true if the debug is enabled.
|
|
|
187 |
*
|
|
|
188 |
* @return bool|string true if debug is enabled, false otherwise or a string if no kernel was set
|
|
|
189 |
*/
|
|
|
190 |
public function isDebug(): bool|string
|
|
|
191 |
{
|
|
|
192 |
return $this->data['debug'];
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* Returns true if the Xdebug is enabled.
|
|
|
197 |
*/
|
|
|
198 |
public function hasXdebug(): bool
|
|
|
199 |
{
|
|
|
200 |
return $this->data['xdebug_enabled'];
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
/**
|
|
|
204 |
* Returns true if the function xdebug_info is available.
|
|
|
205 |
*/
|
|
|
206 |
public function hasXdebugInfo(): bool
|
|
|
207 |
{
|
|
|
208 |
return \function_exists('xdebug_info');
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
/**
|
|
|
212 |
* Returns true if APCu is enabled.
|
|
|
213 |
*/
|
|
|
214 |
public function hasApcu(): bool
|
|
|
215 |
{
|
|
|
216 |
return $this->data['apcu_enabled'];
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* Returns true if Zend OPcache is enabled.
|
|
|
221 |
*/
|
|
|
222 |
public function hasZendOpcache(): bool
|
|
|
223 |
{
|
|
|
224 |
return $this->data['zend_opcache_enabled'];
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public function getBundles()
|
|
|
228 |
{
|
|
|
229 |
return $this->data['bundles'];
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
/**
|
|
|
233 |
* Gets the PHP SAPI name.
|
|
|
234 |
*/
|
|
|
235 |
public function getSapiName(): string
|
|
|
236 |
{
|
|
|
237 |
return $this->data['sapi_name'];
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
public function getName(): string
|
|
|
241 |
{
|
|
|
242 |
return 'config';
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
private function determineSymfonyState(): string
|
|
|
246 |
{
|
|
|
247 |
$now = new \DateTimeImmutable();
|
|
|
248 |
$eom = \DateTimeImmutable::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
|
|
|
249 |
$eol = \DateTimeImmutable::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
|
|
|
250 |
|
|
|
251 |
if ($now > $eol) {
|
|
|
252 |
$versionState = 'eol';
|
|
|
253 |
} elseif ($now > $eom) {
|
|
|
254 |
$versionState = 'eom';
|
|
|
255 |
} elseif ('' !== Kernel::EXTRA_VERSION) {
|
|
|
256 |
$versionState = 'dev';
|
|
|
257 |
} else {
|
|
|
258 |
$versionState = 'stable';
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
return $versionState;
|
|
|
262 |
}
|
|
|
263 |
}
|