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

Commit 2518755

Browse filesBrowse files
committed
Fixed caching of templates in default path on cache warmup
1 parent 0934464 commit 2518755
Copy full SHA for 2518755

File tree

Expand file treeCollapse file tree

3 files changed

+23
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-11
lines changed

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<argument type="service" id="kernel" />
4242
<argument>%kernel.root_dir%</argument>
4343
<argument type="collection" /> <!-- Twig paths -->
44+
<argument>%twig.default_path%</argument>
4445
</service>
4546

4647
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer">

‎src/Symfony/Bundle/TwigBundle/TemplateIterator.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TemplateIterator.php
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ class TemplateIterator implements \IteratorAggregate
2525
private $rootDir;
2626
private $templates;
2727
private $paths;
28+
private $defaultPath;
2829

2930
/**
3031
* @param KernelInterface $kernel A KernelInterface instance
3132
* @param string $rootDir The directory where global templates can be stored
3233
* @param array $paths Additional Twig paths to warm
3334
*/
34-
public function __construct(KernelInterface $kernel, string $rootDir, array $paths = array())
35+
public function __construct(KernelInterface $kernel, string $rootDir, array $paths = array(), $defaultPath = null)
3536
{
3637
$this->kernel = $kernel;
3738
$this->rootDir = $rootDir;
3839
$this->paths = $paths;
40+
$this->defaultPath = $defaultPath;
3941
}
4042

4143
/**
@@ -47,7 +49,10 @@ public function getIterator()
4749
return $this->templates;
4850
}
4951

50-
$this->templates = $this->findTemplatesInDirectory($this->rootDir.'/Resources/views');
52+
$this->templates = array_merge(
53+
$this->findTemplatesInDirectory($this->rootDir.'/Resources/views'),
54+
$this->findTemplatesInDirectory($this->defaultPath, null, array('bundles'))
55+
);
5156
foreach ($this->kernel->getBundles() as $bundle) {
5257
$name = $bundle->getName();
5358
if ('Bundle' === substr($name, -6)) {
@@ -57,7 +62,8 @@ public function getIterator()
5762
$this->templates = array_merge(
5863
$this->templates,
5964
$this->findTemplatesInDirectory($bundle->getPath().'/Resources/views', $name),
60-
$this->findTemplatesInDirectory($this->rootDir.'/'.$bundle->getName().'/views', $name)
65+
$this->findTemplatesInDirectory($this->rootDir.'/'.$bundle->getName().'/views', $name),
66+
$this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name)
6167
);
6268
}
6369

@@ -71,19 +77,19 @@ public function getIterator()
7177
/**
7278
* Find templates in the given directory.
7379
*
74-
* @param string $dir The directory where to look for templates
80+
* @param string $dir The directory where to look for templates
7581
* @param string|null $namespace The template namespace
7682
*
7783
* @return array
7884
*/
79-
private function findTemplatesInDirectory($dir, $namespace = null)
85+
private function findTemplatesInDirectory($dir, $namespace = null, array $excludeDirs = array())
8086
{
8187
if (!is_dir($dir)) {
8288
return array();
8389
}
8490

8591
$templates = array();
86-
foreach (Finder::create()->files()->followLinks()->in($dir) as $file) {
92+
foreach (Finder::create()->files()->followLinks()->in($dir)->exclude($excludeDirs) as $file) {
8793
$templates[] = (null !== $namespace ? '@'.$namespace.'/' : '').str_replace('\\', '/', $file->getRelativePathname());
8894
}
8995

‎src/Symfony/Bundle/TwigBundle/Tests/TemplateIteratorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/TemplateIteratorTest.php
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@ class TemplateIteratorTest extends TestCase
1717
{
1818
public function testGetIterator()
1919
{
20-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
21-
$bundle->expects($this->any())->method('getName')->will($this->returnValue('BarBundle'));
22-
$bundle->expects($this->any())->method('getPath')->will($this->returnValue(__DIR__.'/Fixtures/templates/BarBundle'));
20+
$barBundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
21+
$barBundle->expects($this->any())->method('getName')->will($this->returnValue('BarBundle'));
22+
$barBundle->expects($this->any())->method('getPath')->will($this->returnValue(__DIR__.'/Fixtures/templates/BarBundle'));
23+
24+
$twigBundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
25+
$twigBundle->expects($this->any())->method('getName')->will($this->returnValue('TwigBundle'));
26+
$twigBundle->expects($this->any())->method('getPath')->will($this->returnValue(__DIR__.'/DependencyInjection/Fixtures/Resources/TwigBundle'));
2327

2428
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel')->disableOriginalConstructor()->getMock();
2529
$kernel->expects($this->any())->method('getBundles')->will($this->returnValue(array(
26-
$bundle,
30+
$barBundle, $twigBundle,
2731
)));
28-
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'));
32+
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'), __DIR__.'/DependencyInjection/Fixtures/templates');
2933

3034
$sorted = iterator_to_array($iterator);
3135
sort($sorted);
3236
$this->assertEquals(
3337
array(
3438
'@Bar/index.html.twig',
3539
'@Foo/index.html.twig',
40+
'@Twig/layout.html.twig',
3641
'layout.html.twig',
3742
'sub/sub.html.twig',
3843
),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.