Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fda7e2

Browse filesBrowse files
committed
feature #28809 [HttpKernel] Deprecate the Kernel name (fabpot)
This PR was merged into the 4.2-dev branch. Discussion ---------- [HttpKernel] Deprecate the Kernel name | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #26904 | License | MIT | Doc PR | n/a <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 98ff750 [HttpKernel] deprecated the Kernel name
2 parents d813148 + 98ff750 commit 5fda7e2
Copy full SHA for 5fda7e2

File tree

Expand file treeCollapse file tree

17 files changed

+61
-40
lines changed
Filter options
Expand file treeCollapse file tree

17 files changed

+61
-40
lines changed

‎src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
367367
} else {
368368
$seed = '_'.$container->getParameter('kernel.root_dir');
369369
}
370-
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
370+
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
371371
$namespace = 'sf_'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.ContainerBuilder::hash($seed);
372372

373373
$cacheDriver['namespace'] = $namespace;

‎src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ protected function createContainer(array $data = array())
271271
'kernel.cache_dir' => __DIR__,
272272
'kernel.debug' => false,
273273
'kernel.environment' => 'test',
274-
'kernel.name' => 'kernel',
274+
'kernel.container_class' => 'kernel',
275275
'kernel.root_dir' => __DIR__,
276276
), $data)));
277277
}

‎src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
array('<info>Kernel</>'),
7272
new TableSeparator(),
7373
array('Type', \get_class($kernel)),
74-
array('Name', $kernel->getName()),
7574
array('Environment', $kernel->getEnvironment()),
7675
array('Debug', $kernel->isDebug() ? 'true' : 'false'),
7776
array('Charset', $kernel->getCharset()),

‎src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Application.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function all($namespace = null)
148148
*/
149149
public function getLongVersion()
150150
{
151-
return parent::getLongVersion().sprintf(' (kernel: <comment>%s</>, env: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getName(), $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false');
151+
return parent::getLongVersion().sprintf(' (env: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false');
152152
}
153153

154154
public function add(Command $command)

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testPoolRefsAreWeak()
3030
{
3131
$container = new ContainerBuilder();
3232
$container->setParameter('kernel.debug', false);
33-
$container->setParameter('kernel.name', 'app');
33+
$container->setParameter('kernel.container_class', 'app');
3434
$container->setParameter('kernel.environment', 'prod');
3535
$container->setParameter('kernel.root_dir', 'foo');
3636

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testNamespaceArgumentIsReplaced()
3535
{
3636
$container = new ContainerBuilder();
3737
$container->setParameter('kernel.debug', false);
38-
$container->setParameter('kernel.name', 'app');
38+
$container->setParameter('kernel.container_class', 'app');
3939
$container->setParameter('kernel.environment', 'prod');
4040
$container->setParameter('kernel.root_dir', 'foo');
4141
$adapter = new Definition();
@@ -57,7 +57,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
5757
{
5858
$container = new ContainerBuilder();
5959
$container->setParameter('kernel.environment', 'prod');
60-
$container->setParameter('kernel.name', 'app');
60+
$container->setParameter('kernel.container_class', 'app');
6161
$container->setParameter('kernel.root_dir', 'foo');
6262

6363
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
@@ -75,7 +75,7 @@ public function testArgsAreReplaced()
7575
{
7676
$container = new ContainerBuilder();
7777
$container->setParameter('kernel.debug', false);
78-
$container->setParameter('kernel.name', 'app');
78+
$container->setParameter('kernel.container_class', 'app');
7979
$container->setParameter('kernel.environment', 'prod');
8080
$container->setParameter('cache.prefix.seed', 'foo');
8181
$cachePool = new Definition();
@@ -100,7 +100,7 @@ public function testWithNameAttribute()
100100
{
101101
$container = new ContainerBuilder();
102102
$container->setParameter('kernel.debug', false);
103-
$container->setParameter('kernel.name', 'app');
103+
$container->setParameter('kernel.container_class', 'app');
104104
$container->setParameter('kernel.environment', 'prod');
105105
$container->setParameter('cache.prefix.seed', 'foo');
106106
$cachePool = new Definition();
@@ -126,7 +126,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
126126
{
127127
$container = new ContainerBuilder();
128128
$container->setParameter('kernel.debug', false);
129-
$container->setParameter('kernel.name', 'app');
129+
$container->setParameter('kernel.container_class', 'app');
130130
$container->setParameter('kernel.environment', 'prod');
131131
$container->setParameter('kernel.root_dir', 'foo');
132132
$adapter = new Definition();

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function getName()
49+
public function getContainerClass()
5050
{
51-
if (null === $this->name) {
52-
$this->name = parent::getName().substr(md5($this->rootConfig), -16);
53-
}
54-
55-
return $this->name;
51+
return parent::getContainerClass().substr(md5($this->rootConfig), -16);
5652
}
5753

5854
public function registerBundles()

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@
5050
</span>
5151
</div>
5252

53-
{% if 'n/a' is not same as(collector.appname) %}
54-
<div class="sf-toolbar-info-piece">
55-
<b>Kernel name</b>
56-
<span>{{ collector.appname }}</span>
57-
</div>
58-
{% endif %}
59-
6053
{% if 'n/a' is not same as(collector.env) %}
6154
<div class="sf-toolbar-info-piece">
6255
<b>Environment</b>

‎src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(ContainerBuilder $container)
5252
} else {
5353
$seed = '_'.$container->getParameter('kernel.root_dir');
5454
}
55-
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
55+
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment');
5656

5757
$pools = array();
5858
$clearers = array();

‎src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testPoolRefsAreWeak()
2727
{
2828
$container = new ContainerBuilder();
2929
$container->setParameter('kernel.debug', false);
30-
$container->setParameter('kernel.name', 'app');
30+
$container->setParameter('kernel.container_class', 'app');
3131
$container->setParameter('kernel.environment', 'prod');
3232
$container->setParameter('kernel.root_dir', 'foo');
3333

‎src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testNamespaceArgumentIsReplaced()
3232
{
3333
$container = new ContainerBuilder();
3434
$container->setParameter('kernel.debug', false);
35-
$container->setParameter('kernel.name', 'app');
35+
$container->setParameter('kernel.container_class', 'app');
3636
$container->setParameter('kernel.environment', 'prod');
3737
$container->setParameter('kernel.root_dir', 'foo');
3838
$adapter = new Definition();
@@ -54,7 +54,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
5454
{
5555
$container = new ContainerBuilder();
5656
$container->setParameter('kernel.environment', 'prod');
57-
$container->setParameter('kernel.name', 'app');
57+
$container->setParameter('kernel.container_class', 'app');
5858
$container->setParameter('kernel.root_dir', 'foo');
5959

6060
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
@@ -72,7 +72,7 @@ public function testArgsAreReplaced()
7272
{
7373
$container = new ContainerBuilder();
7474
$container->setParameter('kernel.debug', false);
75-
$container->setParameter('kernel.name', 'app');
75+
$container->setParameter('kernel.container_class', 'app');
7676
$container->setParameter('kernel.environment', 'prod');
7777
$container->setParameter('cache.prefix.seed', 'foo');
7878
$cachePool = new Definition();
@@ -97,7 +97,7 @@ public function testWithNameAttribute()
9797
{
9898
$container = new ContainerBuilder();
9999
$container->setParameter('kernel.debug', false);
100-
$container->setParameter('kernel.name', 'app');
100+
$container->setParameter('kernel.container_class', 'app');
101101
$container->setParameter('kernel.environment', 'prod');
102102
$container->setParameter('cache.prefix.seed', 'foo');
103103
$cachePool = new Definition();
@@ -123,7 +123,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
123123
{
124124
$container = new ContainerBuilder();
125125
$container->setParameter('kernel.debug', false);
126-
$container->setParameter('kernel.name', 'app');
126+
$container->setParameter('kernel.container_class', 'app');
127127
$container->setParameter('kernel.environment', 'prod');
128128
$container->setParameter('kernel.root_dir', 'foo');
129129
$adapter = new Definition();

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* deprecated `KernelInterface::getName()` and the `kernel.name` parameter
8+
49
4.1.0
510
-----
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function collect(Request $request, Response $response, \Exception $except
6060
'token' => $response->headers->get('X-Debug-Token'),
6161
'symfony_version' => Kernel::VERSION,
6262
'symfony_state' => 'unknown',
63-
'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a',
63+
'name' => 'n/a',
6464
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
6565
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
6666
'php_version' => PHP_VERSION,
@@ -227,6 +227,8 @@ public function getPhpTimezone()
227227
* Gets the application name.
228228
*
229229
* @return string The application name
230+
*
231+
* @deprecated since Symfony 4.2
230232
*/
231233
public function getAppName()
232234
{

‎src/Symfony/Component/HttpKernel/Kernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Kernel.php
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
5858
protected $environment;
5959
protected $debug;
6060
protected $booted = false;
61+
/**
62+
* @deprecated since Symfony 4.2
63+
*/
6164
protected $name;
6265
protected $startTime;
6366

@@ -81,7 +84,7 @@ public function __construct(string $environment, bool $debug)
8184
$this->environment = $environment;
8285
$this->debug = $debug;
8386
$this->rootDir = $this->getRootDir();
84-
$this->name = $this->getName();
87+
$this->name = $this->getName(false);
8588
}
8689

8790
public function __clone()
@@ -271,8 +274,12 @@ public function locateResource($name, $dir = null, $first = true)
271274
/**
272275
* {@inheritdoc}
273276
*/
274-
public function getName()
277+
public function getName(/* $triggerDeprecation = true */)
275278
{
279+
if (0 === \func_num_args() || func_get_arg(0)) {
280+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
281+
}
282+
276283
if (null === $this->name) {
277284
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
278285
if (ctype_digit($this->name[0])) {
@@ -424,7 +431,7 @@ protected function build(ContainerBuilder $container)
424431
*/
425432
protected function getContainerClass()
426433
{
427-
return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
434+
return str_replace('\\', '_', \get_class($this)).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
428435
}
429436

430437
/**
@@ -579,6 +586,9 @@ protected function getKernelParameters()
579586
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
580587
'kernel.environment' => $this->environment,
581588
'kernel.debug' => $this->debug,
589+
/*
590+
* @deprecated since Symfony 4.2
591+
*/
582592
'kernel.name' => $this->name,
583593
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
584594
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),

‎src/Symfony/Component/HttpKernel/KernelInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/KernelInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public function locateResource($name, $dir = null, $first = true);
100100
* Gets the name of the kernel.
101101
*
102102
* @return string The kernel name
103+
*
104+
* @deprecated since Symfony 4.2
103105
*/
104106
public function getName();
105107

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testCollect()
3030
$this->assertSame('test', $c->getEnv());
3131
$this->assertTrue($c->isDebug());
3232
$this->assertSame('config', $c->getName());
33-
$this->assertSame('testkernel', $c->getAppName());
33+
$this->assertSame('n/a', $c->getAppName());
3434
$this->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
3535
$this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
3636
$this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());

‎src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/KernelTest.php
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testInitializeContainerClearsOldContainers()
7575
$kernel->boot();
7676

7777
$containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);
78-
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'));
78+
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
7979
$this->assertFileExists($containerDir);
8080
$this->assertFileNotExists($containerDir.'.legacy');
8181

@@ -302,13 +302,19 @@ public function testGetRootDir()
302302
$this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
303303
}
304304

305+
/**
306+
* @group legacy
307+
*/
305308
public function testGetName()
306309
{
307310
$kernel = new KernelForTest('test', true);
308311

309312
$this->assertEquals('Fixtures', $kernel->getName());
310313
}
311314

315+
/**
316+
* @group legacy
317+
*/
312318
public function testOverrideGetName()
313319
{
314320
$kernel = new KernelForOverrideName('test', true);
@@ -506,6 +512,9 @@ public function testKernelWithoutBundles()
506512
$this->assertTrue($kernel->getContainer()->getParameter('test_executed'));
507513
}
508514

515+
/**
516+
* @group legacy
517+
*/
509518
public function testKernelRootDirNameStartingWithANumber()
510519
{
511520
$dir = __DIR__.'/Fixtures/123';
@@ -532,14 +541,14 @@ public function testKernelReset()
532541

533542
$containerClass = \get_class($kernel->getContainer());
534543
$containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();
535-
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
544+
unlink(__DIR__.'/Fixtures/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
536545

537546
$kernel = new CustomProjectDirKernel();
538547
$kernel->boot();
539548

540549
$this->assertInstanceOf($containerClass, $kernel->getContainer());
541550
$this->assertFileExists($containerFile);
542-
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
551+
unlink(__DIR__.'/Fixtures/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
543552

544553
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
545554
$kernel->boot();
@@ -707,9 +716,9 @@ class CustomProjectDirKernel extends Kernel
707716
private $buildContainer;
708717
private $httpKernel;
709718

710-
public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $name = 'custom')
719+
public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $env = 'custom')
711720
{
712-
parent::__construct($name, true);
721+
parent::__construct($env, true);
713722

714723
$this->baseDir = 'foo';
715724
$this->buildContainer = $buildContainer;
@@ -725,6 +734,11 @@ public function registerContainerConfiguration(LoaderInterface $loader)
725734
{
726735
}
727736

737+
protected function getContainerClass()
738+
{
739+
return $this->name.parent::getContainerClass();
740+
}
741+
728742
public function getProjectDir()
729743
{
730744
return $this->baseDir;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.