8000 [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes by nicolas-grekas · Pull Request #21381 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes #21381

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

Merged
merged 1 commit into from
Jan 24, 2017
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
[FrameworkBundle] Dont wire "annotations.cached_reader" before removi…
…ng passes
  • Loading branch information
nicolas-grekas committed Jan 24, 2017
commit e59f0e0fd7323902fa025e2eae96ce9eb91b24c5
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
class AddAnnotationsCachedReaderPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
// "annotations.cached_reader" is wired late so that any passes using
// "annotation_reader" at build time don't get any cache
if ($container->hasDefinition('annotations.cached_reader')) {
$container->setAlias('annotation_reader', 'annotations.cached_reader');
}
}
}
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]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
->replaceArgument(2, $config['debug'])
->addAutowiringType(Reader::class)
;
$container->setAlias('annotation_reader', 'annotations.cached_reader');
} else {
$container->removeDefinition('annotations.cached_reader');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle;

use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
Expand Down Expand Up @@ -79,6 +80,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new TemplatingPass());
$container->addCompilerPass(new AddConstraintValidatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new AddValidatorInitializersPass());
$container->addCompilerPass(new AddConsoleCommandPass());
$container->addCompilerPass(new FormPass());
Expand Down
9 changes: 2 additions & 7 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
<tag name="cache.pool" />
</service>

<service id="cache.annotations" class="Symfony\Component\Cache\Adapter\AdapterInterface" public="false">
<factory class="Symfony\Component\Cache\Adapter\AbstractAdapter" method="createSystemCache" />
<tag name="cache.pool" clearer="cache.default_clearer" />
<argument /> <!-- namespace -->
<argument>0</argument> <!-- default lifetime -->
<argument /> <!-- version -->
<argument>%kernel.cache_dir%/pools</argument>
<service id="cache.annotations" parent="cache.system" public="false">
<tag name="cache.pool" />
</service>

<service id="cache.adapter.system" class="Symfony\Component\Cache\Adapter\AdapterInterface" abstract="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ public function testAnnotations()
$container = $this->createContainerFromFile('full');

$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache')->getArgument(0));
$this->assertSame('annotations.cached_reader', (string) $container->getAlias('annotation_reader'));
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotations.cached_reader')->getArgument(1));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\Bundle\TestBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AnnotationReaderPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// simulate u 1E0A sing "annotation_reader" in a compiler pass
$container->get('annotation_reader');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\AnnotationReaderPass;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;

class TestBundle extends Bundle
Expand All @@ -25,5 +26,7 @@ public function build(ContainerBuilder $container)
$extension = $container->getExtension('test');

$extension->setCustomConfig(new CustomConfig());

$container->addCompilerPass(new AnnotationReaderPass());
}
}
0