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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
} else {
$seed = '_'.$container->getParameter('kernel.project_dir');
}
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
$seed .= '.'.$container->getParameter('kernel.container_class');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kernel.container_class already embeds the entropy from kernel.environment and kernel.debug

$namespace = 'sf_'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.ContainerBuilder::hash($seed);

$cacheDriver['namespace'] = $namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ protected function createContainer(array $data = array())
return new ContainerBuilder(new ParameterBag(array_merge(array(
'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'),
'kernel.cache_dir' => __DIR__,
'kernel.debug' => false,
'kernel.environment' => 'test',
'kernel.container_class' => 'kernel',
'kernel.project_dir' => __DIR__,
), $data)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<service id="data_collector.config" class="Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector">
<tag name="data_collector" template="@WebProfiler/Collector/config.html.twig" id="config" priority="-255" />
<call method="setKernel"><argument type="service" id="kernel" on-invalid="ignore" /></call>
<argument type="service">
<service class="string">
<factory function="basename" />
<argument>%kernel.project_dir%</argument>
</service>
</argument>
</service>

<service id="data_collector.request" class="Symfony\Component\HttpKernel\DataCollector\RequestDataCollector">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class CachePoolClearerPassTest extends TestCase
public function testPoolRefsAreWeak()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');

$globalClearer = new Definition(Psr6CacheClearer::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ protected function setUp()
public function testNamespaceArgumentIsReplaced()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
Expand All @@ -50,13 +48,12 @@ public function testNamespaceArgumentIsReplaced()

$this->cachePoolPass->process($container);

$this->assertSame('D07rhFx97S', $cachePool->getArgument(0));
$this->assertSame('z3X945Jbf5', $cachePool->getArgument(0));
}

public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.project_dir', 'foo');

Expand All @@ -74,9 +71,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
public function testArgsAreReplaced()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('cache.prefix.seed', 'foo');
$cachePool = new Definition();
$cachePool->addTag('cache.pool', array(
Expand All @@ -92,16 +87,14 @@ public function testArgsAreReplaced()

$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
$this->assertSame('itantF+pIq', $cachePool->getArgument(1));
$this->assertSame('tQNhcV-8xa', $cachePool->getArgument(1));
$this->assertSame(3, $cachePool->getArgument(2));
}

public function testWithNameAttribute()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('cache.prefix.seed', 'foo');
$cachePool = new Definition();
$cachePool->addTag('cache.pool', array(
Expand All @@ -115,7 +108,7 @@ public function testWithNameAttribute()

$this->cachePoolPass->process($container);

$this->assertSame('9HvPgAayyh', $cachePool->getArgument(1));
$this->assertSame('+naTpPa4Sm', $cachePool->getArgument(1));
}

/**
Expand All @@ -125,9 +118,7 @@ public function testWithNameAttribute()
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@
<span class="label">Symfony version</span>
</div>

{% if 'n/a' != collector.appname %}
<div class="metric">
<span class="value">{{ collector.appname }}</span>
<span class="label">Application name</span>
</div>
{% endif %}

{% if 'n/a' != collector.env %}
<div class="metric">
<span class="value">{{ collector.env }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function process(ContainerBuilder $container)
} else {
$seed = '_'.$container->getParameter('kernel.project_dir');
}
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment');
$seed .= '.'.$container->getParameter('kernel.container_class');

$pools = array();
$clearers = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class CachePoolClearerPassTest extends TestCase
public function testPoolRefsAreWeak()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');

$globalClearer = new Definition(Psr6CacheClearer::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ protected function setUp()
public function testNamespaceArgumentIsReplaced()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
Expand All @@ -47,13 +45,12 @@ public function testNamespaceArgumentIsReplaced()

$this->cachePoolPass->process($container);

$this->assertSame('D07rhFx97S', $cachePool->getArgument(0));
$this->assertSame('z3X945Jbf5', $cachePool->getArgument(0));
}

public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.project_dir', 'foo');

Expand All @@ -71,9 +68,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
public function testArgsAreReplaced()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('cache.prefix.seed', 'foo');
$cachePool = new Definition();
$cachePool->addTag('cache.pool', array(
Expand All @@ -89,16 +84,14 @@ public function testArgsAreReplaced()

$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
$this->assertSame('itantF+pIq', $cachePool->getArgument(1));
$this->assertSame('tQNhcV-8xa', $cachePool->getArgument(1));
$this->assertSame(3, $cachePool->getArgument(2));
}

public function testWithNameAttribute()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('cache.prefix.seed', 'foo');
$cachePool = new Definition();
$cachePool->addTag('cache.pool', array(
Expand All @@ -112,7 +105,7 @@ public function testWithNameAttribute()

$this->cachePoolPass->process($container);

$this->assertSame('9HvPgAayyh', $cachePool->getArgument(1));
$this->assertSame('+naTpPa4Sm', $cachePool->getArgument(1));
}

/**
Expand All @@ -122,9 +115,7 @@ public function testWithNameAttribute()
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function collect(Request $request, Response $response, \Exception $except
'token' => $response->headers->get('X-Debug-Token'),
'symfony_version' => Kernel::VERSION,
'symfony_state' => 'unknown',
'name' => 'n/a',
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
'php_version' => PHP_VERSION,
Expand Down Expand Up @@ -232,7 +231,9 @@ public function getPhpTimezone()
*/
public function getAppName()
{
return $this->data['name'];
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);

return 'n/a';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ public function locateResource($name, $dir = null, $first = true)

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's be even more explicit and duplicate this info from the interface

*/
public function getName(/* $triggerDeprecation = true */)
{
Expand Down Expand Up @@ -440,7 +442,7 @@ protected function build(ContainerBuilder $container)
*/
protected function getContainerClass()
{
return str_replace('\\', '_', \get_class($this)).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
return $this->name.str_replace('\\', '_', \get_class($this)).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the $this->name prefix is a requirement here. The failing tests on lower branches hint this is a BC break for multi-kernel apps that generate a different container per name.
Once ppl will have moved out of using name, then we will be free to remove it - in 5.0.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function testCollect()
$this->assertSame('test', $c->getEnv());
$this->assertTrue($c->isDebug());
$this->assertSame('config', $c->getName());
$this->assertSame('n/a', $c->getAppName());
$this->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
$this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
$this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testInitializeContainerClearsOldContainers()
$kernel->boot();

$containerDir = __DIR__.'/Fixtures/var/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);
$this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
$this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
$this->assertFileExists($containerDir);
$this->assertFileNotExists($containerDir.'.legacy');

Expand Down Expand Up @@ -533,14 +533,14 @@ public function testKernelReset()

$containerClass = \get_class($kernel->getContainer());
$containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();
unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
unlink(__DIR__.'/Fixtures/var/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');

$kernel = new CustomProjectDirKernel();
$kernel->boot();

$this->assertInstanceOf($containerClass, $kernel->getContainer());
$this->assertFileExists($containerFile);
unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
unlink(__DIR__.'/Fixtures/var/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');

$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();
Expand Down