Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce81b5b

Browse files
committed
[HttpKernel] deprecated the Kernel name
1 parent 61d336b commit ce81b5b

File tree

17 files changed

+52
-30
lines changed

17 files changed

+52
-30
lines changed

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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
4949
public function getName()
5050
{
5151
if (null === $this->name) {
52-
$this->name = parent::getName().substr(md5($this->rootConfig), -16);
52+
$this->name = substr(md5($this->rootConfig), -16);
5353
}
5454

5555
return $this->name;

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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
5555
protected $environment;
5656
protected $debug;
5757
protected $booted = false;
58+
/**
59+
* @deprecated since Symfony 4.2
60+
*/
5861
protected $name;
5962
protected $startTime;
6063

@@ -78,7 +81,7 @@ public function __construct(string $environment, bool $debug)
7881
$this->environment = $environment;
7982
$this->debug = $debug;
8083
$this->rootDir = $this->getRootDir();
81-
$this->name = $this->getName();
84+
$this->name = $this->getName(false);
8285
}
8386

8487
public function __clone()
@@ -268,8 +271,12 @@ public function locateResource($name, $dir = null, $first = true)
268271
/**
269272
* {@inheritdoc}
270273
*/
271-
public function getName()
274+
public function getName(/* $triggerDeprecation = true */)
272275
{
276+
if (0 === \func_num_args() || func_get_arg(0)) {
277+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
278+
}
279+
273280
if (null === $this->name) {
274281
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
275282
if (ctype_digit($this->name[0])) {
@@ -421,7 +428,9 @@ protected function build(ContainerBuilder $container)
421428
*/
422429
protected function getContainerClass()
423430
{
424-
return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
431+
$r = new \ReflectionObject($this);
432+
433+
return 'app'.md5($r->getFileName()).ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer';
425434
}
426435

427436
/**
@@ -576,6 +585,9 @@ protected function getKernelParameters()
576585
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
577586
'kernel.environment' => $this->environment,
578587
'kernel.debug' => $this->debug,
588+
/**
589+
* @deprecated since Symfony 4.2
590+
*/
579591
'kernel.name' => $this->name,
580592
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
581593
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),

src/Symfony/Component/HttpKernel/KernelInterface.php

Lines 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

Lines 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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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';

0 commit comments

Comments
 (0)