8000 [HttpKernel] ConfigDataCollector to return known data without the nee… · symfony/symfony@d919f2c · GitHub
[go: up one dir, main page]

Skip to content

Commit d919f2c

Browse files
topikitoNyholm
authored andcommitted
[HttpKernel] ConfigDataCollector to return known data without the need of a Kernel
1 parent a2d534c commit d919f2c

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,19 @@ public function setKernel(KernelInterface $kernel = null)
5959
*/
6060
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
6161
{
62+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
63+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
64+
6265
$this->data = [
6366
'app_name' => $this->name,
6467
'app_version' => $this->version,
6568
'token' => $response->headers->get('X-Debug-Token'),
6669
'symfony_version' => Kernel::VERSION,
67-
'symfony_state' => 'unknown',
70+
'symfony_minor_version' => sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION),
71+
'symfony_lts' => 4 === Kernel::MINOR_VERSION,
72+
'symfony_state' => $this->determineSymfonyState(),
73+
'symfony_eom' => $eom->format('F Y'),
74+
'symfony_eol' => $eol->format('F Y'),
6875
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
6976
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
7077
'php_version' => \PHP_VERSION,
@@ -82,14 +89,6 @@ public function collect(Request $request, Response $response/*, \Throwable $exce
8289
foreach ($this->kernel->getBundles() as $name => $bundle) {
8390
$this->data['bundles'][$name] = new ClassStub(\get_class($bundle));
8491
}
85-
86-
$this->data['symfony_state'] = $this->determineSymfonyState();
87-
$this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
88-
$this->data['symfony_lts'] = 4 === Kernel::MINOR_VERSION;
89-
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
90-
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
91-
$this->data['symfony_eom'] = $eom->format('F Y');
92-
$this->data['symfony_eol'] = $eol->format('F Y');
9392
}
9493

9594
if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {

src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function testCollect()
4141
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
4242
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
4343
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
44+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
45+
$this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']);
46+
47+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
48+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
49+
$this->assertSame($eom, $c->getSymfonyEom());
50+
$this->assertSame($eol, $c->getSymfonyEol());
4451
}
4552

4653
/**
@@ -58,6 +65,34 @@ public function testLegacy()
5865
$this->assertSame('name', $c->getApplicationName());
5966
$this->assertNull($c->getApplicationVersion());
6067
}
68+
69+
public function testCollectWithoutKernel()
70+
{
71+
$c = new ConfigDataCollector();
72+
$c->collect(new Request(), new Response());
73+
74+
$this->assertSame('n/a', $c->getEnv());
75+
$this->assertSame('n/a', $c->isDebug());
76+
$this->assertSame('config', $c->getName());
77+
$this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION);
78+
$this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION);
79+
$this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture());
80+
$this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
81+
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
82+
$this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
83+
$this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts());
84+
$this->assertNull($c->getToken());
85+
$this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
86+
$this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
87+
$this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
88+
$this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion());
89+
$this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']);
90+
91+
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y');
92+
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y');
93+
$this->assertSame($eom, $c->getSymfonyEom());
94+
$this->assertSame($eol, $c->getSymfonyEol());
95+
}
6196
}
6297

6398
class KernelForTest extends Kernel

0 commit comments

Comments
 (0)
0