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

Fixed CachePoolClearerPass fails if "cache.annotations" service is created #21362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class CacheAnnotationsMonologInjectorPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('cache.annotations') && !$container->hasAlias('cache.annotations')) {
return;
}
$factory = array(AbstractAdapter::class, 'createSystemCache');
$annotationsPool = $container->findDefinition('cache.annotations');
if ($factory !== $annotationsPool->getFactory() || 4 !== count($annotationsPool->getArguments())) {
return;
}
if ($container->has('monolog.logger.cache')) {
$annotationsPool->addArgument(new Reference('monolog.logger.cache'));
} elseif ($container->hasDefinition('cache.system')) {
$systemPool = $container->getDefinition('cache.system');
if ($factory === $systemPool->getFactory() && 5 <= count($systemArgs = $systemPool->getArguments())) {
$annotationsPool->addArgument($systemArgs[4]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -39,22 +38,5 @@ public function process(ContainerBuilder $container)
}
}
}

if (!$container->has('cache.annotations')) {
return;
}
$factory = array(AbstractAdapter::class, 'createSystemCache');
$annotationsPool = $container->getDefinition('cache.annotations');
if ($factory !== $annotationsPool->getFactory() || 4 !== count($annotationsPool->getArguments())) {
return;
}
if ($container->has('monolog.logger.cache')) {
$annotationsPool->addArgument(new Reference('monolog.logger.cache'));
} elseif ($container->has('cache.system')) {
$systemPool = $container->getDefinition('cache.system');
if ($factory === $systemPool->getFactory() && 5 <= count($systemArgs = $systemPool->getArguments())) {
$annotationsPool->addArgument($systemArgs[4]);
}
}
}
}
2 changes: 2 additions & 0 deletions 2 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheAnnotationsMonologInjectorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
Expand Down Expand Up @@ -96,6 +97,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
$container->addCompilerPass(new ValidateWorkflowsPass());
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new CacheAnnotationsMonologInjectorPass(), PassConfig::TYPE_BEFORE_REMOVING, 32);

if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ public function testContainerCompilation()

$this->assertTrue($client->getContainer()->has('serializer'));
}

/**
* @see https://github.com/symfony/symfony/issues/21339
*/
public function testContainerCompilationErrorDueCachePoolClearerPassBug()
{
$client = $this->createClient(array('test_case' => 'ContainerDumpCacheAnnotationsBug', 'root_config' => 'config.yml', 'debug' => true));

$this->assertTrue($client->getContainer()->has('serializer'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app\ContainerDumpCacheAnnotationsBug;

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class BeforeOptimizationCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// force to use service in compiler pass which does DiExtraBundle
$container->get('cache.annotations');
}
}

/**
* Emulate CacheCollectorPass which aliasias cache.annotations service (used in debug mode).
*
* @see src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CacheCollectorPass.php:24
*/
class CacheCollectorEmulationPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$id = 'cache.annotations';

$container->register($id.'.recorder', DummyDecorator::class)
->setDecoratedService($id)
->addArgument(new Reference($id.'.recorder.inner'))
->setPublic(false);
}
}

class DummyDecorator implements CacheItemPoolInterface
{
public function getItem($key)
{
}

public function getItems(array $keys = array())
{
}

public function hasItem($key)
{
}

public function clear()
{
}

public function deleteItem($key)
{
}

public function deleteItems(array $keys)
{
}

public function save(CacheItemInterface $item)
{
}

public function saveDeferred(CacheItemInterface $item)
{
}

public function commit()
{
}
}

class SetupBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new BeforeOptimizationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
$container->addCompilerPass(new CacheCollectorEmulationPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Bundle\FrameworkBundle\Tests\Functional\app\ContainerDumpCacheAnnotationsBug\SetupBundle;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return array(
new FrameworkBundle(),
new TestBundle(),
new SetupBundle(),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
imports:
- { resource: ../config/default.yml }

framework:
esi: true
ssi: true
fragments: true
profiler: true
router: true
session: true
request: true
templating:
enabled: true
engines: ['php']
assets: true
translator: true
validation: true
serializer: true
property_info: true
csrf_protection: true
form: true
Morty Proxy This is a proxified and sanitized view of the page, visit original site.