Skip to content

Commit 1bee96d

Browse files
[FrameworkBundle] Fine-tune generated annotations.php cache
1 parent 19f15d7 commit 1bee96d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@
2727
class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
2828
{
2929
private $annotationReader;
30+
private $excludeRegexp;
3031

3132
/**
3233
* @param Reader $annotationReader
3334
* @param string $phpArrayFile The PHP file where annotations are cached
3435
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered annotations are cached
3536
*/
36-
public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
37+
public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool, $excludeRegexp = null)
3738
{
3839
parent::__construct($phpArrayFile, $fallbackPool);
3940
$this->annotationReader = $annotationReader;
41+
$this->excludeRegexp = $excludeRegexp;
4042
}
4143

4244
/**
@@ -54,6 +56,9 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
5456
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter));
5557

5658
foreach ($annotatedClasses as $class) {
59+
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {
60+
continue;
61+
}
5762
try {
5863
$this->readAllComponents($reader, $class);
5964
} catch (\ReflectionException $e) {

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ public function load(array $configs, ContainerBuilder $container)
310310
'**\\Entity\\',
311311

312312
// Added explicitly so that we don't rely on the class map being dumped to make it work
313+
'Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController',
313314
'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
314315
));
315316

Resources/config/annotations.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<argument type="service" id="annotations.reader" />
3838
<argument>%kernel.cache_dir%/annotations.php</argument>
3939
<argument type="service" id="cache.annotations" />
40+
<argument>#^Symfony\\(?:Component\\HttpKernel\\|Bundle\\FrameworkBundle\\Controller\\(?!AbstractController$|Controller$))#</argument>
4041
</service>
4142

4243
<service id="annotations.cache" class="Symfony\Component\Cache\DoctrineProvider">

0 commit comments

Comments
 (0)