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 450632a

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

File tree

Expand file treeCollapse file tree

4 files changed

+16
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+16
-7
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a layout

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/TemplateIteratorTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ public function testGetIterator()
2525
$kernel->expects($this->any())->method('getBundles')->will($this->returnValue(array(
2626
$bundle,
2727
)));
28-
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'));
28+
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'), __DIR__.'/DependencyInjection/Fixtures/templates');
2929

3030
$sorted = iterator_to_array($iterator);
3131
sort($sorted);
3232
$this->assertEquals(
3333
array(
3434
'@Bar/index.html.twig',
35+
'@Bar/layout.html.twig',
3536
'@Foo/index.html.twig',
3637
'layout.html.twig',
3738
'sub/sub.html.twig',

0 commit comments

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