Skip to content

[FrameworkBundle] Wire ArrayCache for annotation reader at bootstrap #21556

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
Feb 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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

/**
* @internal
Expand All @@ -27,7 +28,16 @@ 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');
$reader = $container->getDefinition('annotations.cached_reader');
$tags = $reader->getTags();

if (isset($tags['annotations.cached_reader'][0]['provider'])) {
if ($container->hasAlias($provider = $tags['annotations.cached_reader'][0]['provider'])) {
$provider = (string) $container->getAlias($provider);
}
$container->set('annotations.cached_reader', null);
Copy link
Member

Choose a reason for hiding this comment

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

aren't we deprecating this ?

Copy link
Member Author

@nicolas-grekas nicolas-grekas Feb 7, 2017

Choose a reason for hiding this comment

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

not in #21533 (methodMap is empty in ContainerBuilder), but in #19668 yes - yet I think we should not merge it as explained implicitly :)

$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, new Reference($provider)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,11 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde

$container
->getDefinition('annotations.cached_reader')
->replaceArgument(1, new Reference($cacheService))
->replaceArgument(2, $config['debug'])
->addTag('annotations.cached_reader', array('provider' => $cacheService))
->addAutowiringType(Reader::class)
;
$container->setAlias('annotation_reader', 'annotations.cached_reader');
} else {
$container->removeDefinition('annotations.cached_reader');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

<service id="annotations.cached_reader" class="Doctrine\Common\Annotations\CachedReader" public="false">
<argument type="service" id="annotations.reader" />
<argument /><!-- Cache Implementation -->
<argument type="service">
<service class="Doctrine\Common\Cache\ArrayCache" />
</argument>
<argument /><!-- Debug-Flag -->
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;

use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
Expand Down Expand Up @@ -818,6 +819,7 @@ protected function createContainerFromFile($file, $data = array(), $resetCompile
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
}
$container->getCompilerPassConfig()->setBeforeRemovingPasses(array(new AddAnnotationsCachedReaderPass()));
$container->compile();

return self::$containerCache[$cacheKey] = $container;
Expand Down