Skip to content

Commit d1137f9

Browse files
committed
[TwigBundle] remove legacy template dirs from iterator
1 parent ebd8f21 commit d1137f9

File tree

12 files changed

+13
-33
lines changed

12 files changed

+13
-33
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function process(ContainerBuilder $container)
4646
$coreThemePath = \dirname(\dirname($reflClass->getFileName())).'/Resources/views/Form';
4747
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', [$coreThemePath]);
4848

49-
$paths = $container->getDefinition('twig.template_iterator')->getArgument(2);
49+
$paths = $container->getDefinition('twig.template_iterator')->getArgument(1);
5050
$paths[$coreThemePath] = null;
51-
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
51+
$container->getDefinition('twig.template_iterator')->replaceArgument(1, $paths);
5252
}
5353

5454
if ($container->has('router')) {

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection;
1313

14-
use Symfony\Bundle\TwigBundle\Loader\NativeFilesystemLoader;
1514
use Symfony\Component\Config\FileLocator;
1615
use Symfony\Component\Config\Resource\FileExistenceResource;
1716
use Symfony\Component\Console\Application;
@@ -97,7 +96,7 @@ public function load(array $configs, ContainerBuilder $container)
9796
}
9897

9998
// paths are modified in ExtensionPass if forms are enabled
100-
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']);
99+
$container->getDefinition('twig.template_iterator')->replaceArgument(1, $config['paths']);
101100

102101
foreach ($this->getBundleTemplatePaths($container, $config) as $name => $paths) {
103102
$namespace = $this->normalizeBundleName($name);

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

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
<service id="twig.template_iterator" class="Symfony\Bundle\TwigBundle\TemplateIterator">
3333
<argument type="service" id="kernel" />
34-
<argument>%kernel.root_dir%</argument>
3534
<argument type="collection" /> <!-- Twig paths -->
3635
<argument>%twig.default_path%</argument>
3736
</service>

src/Symfony/Bundle/TwigBundle/TemplateIterator.php

+3-18
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,18 @@
2424
class TemplateIterator implements \IteratorAggregate
2525
{
2626
private $kernel;
27-
private $rootDir;
2827
private $templates;
2928
private $paths;
3029
private $defaultPath;
3130

3231
/**
3332
* @param KernelInterface $kernel A KernelInterface instance
34-
* @param string $rootDir The directory where global templates can be stored
3533
* @param array $paths Additional Twig paths to warm
3634
* @param string|null $defaultPath The directory where global templates can be stored
3735
*/
38-
public function __construct(KernelInterface $kernel, string $rootDir, array $paths = [], string $defaultPath = null)
36+
public function __construct(KernelInterface $kernel, array $paths = [], string $defaultPath = null)
3937
{
4038
$this->kernel = $kernel;
41-
$this->rootDir = $rootDir;
4239
$this->paths = $paths;
4340
$this->defaultPath = $defaultPath;
4441
}
@@ -52,14 +49,8 @@ public function getIterator()
5249
return $this->templates;
5350
}
5451

55-
$templates = $this->findTemplatesInDirectory($this->rootDir.'/Resources/views');
52+
$templates = null !== $this->defaultPath ? $this->findTemplatesInDirectory($this->defaultPath, null, ['bundles']) : [];
5653

57-
if (null !== $this->defaultPath) {
58-
$templates = array_merge(
59-
$templates,
60-
$this->findTemplatesInDirectory($this->defaultPath, null, ['bundles'])
61-
);
62-
}
6354
foreach ($this->kernel->getBundles() as $bundle) {
6455
$name = $bundle->getName();
6556
if ('Bundle' === substr($name, -6)) {
@@ -69,14 +60,8 @@ public function getIterator()
6960
$templates = array_merge(
7061
$templates,
7162
$this->findTemplatesInDirectory($bundle->getPath().'/Resources/views', $name),
72-
$this->findTemplatesInDirectory($this->rootDir.'/Resources/'.$bundle->getName().'/views', $name)
63+
null !== $this->defaultPath ? $this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name) : []
7364
);
74-
if (null !== $this->defaultPath) {
75-
$templates = array_merge(
76-
$templates,
77-
$this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name)
78-
);
79-
}
8065
}
8166

8267
foreach ($this->paths as $dir => $namespace) {

src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/BarBundle/views/base.html.twig

Whitespace-only changes.

src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/views/layout.html.twig

-1
This file was deleted.

src/Symfony/Bundle/TwigBundle/Tests/Fixtures/templates/Resources/views/sub/sub.html.twig

-1
This file was deleted.

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ public function testGetIterator()
2525
$kernel->expects($this->any())->method('getBundles')->willReturn([
2626
$bundle,
2727
]);
28-
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', [__DIR__.'/Fixtures/templates/Foo' => 'Foo'], __DIR__.'/DependencyInjection/Fixtures/templates');
28+
$iterator = new TemplateIterator($kernel, [__DIR__.'/Fixtures/templates/Foo' => 'Foo'], __DIR__.'/DependencyInjection/Fixtures/templates');
2929

3030
$sorted = iterator_to_array($iterator);
3131
sort($sorted);
3232
$this->assertEquals(
3333
[
34-
'@Bar/base.html.twig',
3534
'@Bar/index.html.twig',
3635
'@Bar/layout.html.twig',
3736
'@Foo/index.html.twig',
3837
'layout.html.twig',
39-
'sub/sub.html.twig',
4038
],
4139
$sorted
4240
);

src/Symfony/Bundle/TwigBundle/composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/finder": "^4.4|^5.0",
3333
"symfony/form": "^4.4|^5.0",
3434
"symfony/routing": "^4.4|^5.0",
35-
"symfony/translation": "^4.4|^5.0",
35+
"symfony/translation": "^5.0",
3636
"symfony/yaml": "^4.4|^5.0",
3737
"symfony/framework-bundle": "^5.0",
3838
"symfony/web-link": "^4.4|^5.0",
@@ -42,7 +42,7 @@
4242
"conflict": {
4343
"symfony/dependency-injection": "<4.4",
4444
"symfony/framework-bundle": "<5.0",
45-
"symfony/translation": "<4.4"
45+
"symfony/translation": "<5.0"
4646
},
4747
"autoload": {
4848
"psr-4": { "Symfony\\Bundle\\TwigBundle\\": "" },

src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function process(ContainerBuilder $container)
6868
return;
6969
}
7070

71-
$paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(2));
71+
$paths = array_keys($container->getDefinition('twig.template_iterator')->getArgument(1));
7272
if ($container->hasDefinition($this->debugCommandServiceId)) {
7373
$definition = $container->getDefinition($this->debugCommandServiceId);
7474
$definition->replaceArgument(4, $container->getParameter('twig.default_path'));

src/Symfony/Component/Translation/Tests/DependencyInjection/TranslationPassTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testValidCommandsViewPathsArgument()
6868
->setArguments([null, null, null, null, null, null, [], []])
6969
;
7070
$container->register('twig.template_iterator')
71-
->setArguments([null, null, ['other/templates' => null, 'tpl' => 'App']])
71+
->setArguments([null, ['other/templates' => null, 'tpl' => 'App']])
7272
;
7373
$container->setParameter('twig.default_path', 'templates');
7474

@@ -109,7 +109,7 @@ public function testCommandsViewPathsArgumentsAreIgnoredWithOldServiceDefinition
109109
])
110110
;
111111
$container->register('twig.template_iterator')
112-
->setArguments([null, null, ['other/templates' => null, 'tpl' => 'App']])
112+
->setArguments([null, ['other/templates' => null, 'tpl' => 'App']])
113113
;
114114
$container->setParameter('twig.default_path', 'templates');
115115

src/Symfony/Component/Translation/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"conflict": {
3636
"symfony/config": "<4.4",
3737
"symfony/dependency-injection": "<4.4",
38+
"symfony/twig-bundle": "<5.0",
3839
"symfony/yaml": "<4.4"
3940
},
4041
"provide": {

0 commit comments

Comments
 (0)