24
24
class TemplateIterator implements \IteratorAggregate
25
25
{
26
26
private $ kernel ;
27
- private $ rootDir ;
28
27
private $ templates ;
29
28
private $ paths ;
30
29
private $ defaultPath ;
31
30
32
31
/**
33
32
* @param KernelInterface $kernel A KernelInterface instance
34
- * @param string $rootDir The directory where global templates can be stored
35
33
* @param array $paths Additional Twig paths to warm
36
34
* @param string|null $defaultPath The directory where global templates can be stored
37
35
*/
38
- public function __construct (KernelInterface $ kernel , string $ rootDir , array $ paths = [], string $ defaultPath = null )
36
+ public function __construct (KernelInterface $ kernel , array $ paths = [], string $ defaultPath = null )
39
37
{
40
38
$ this ->kernel = $ kernel ;
41
- $ this ->rootDir = $ rootDir ;
42
39
$ this ->paths = $ paths ;
43
40
$ this ->defaultPath = $ defaultPath ;
44
41
}
@@ -52,14 +49,8 @@ public function getIterator()
52
49
return $ this ->templates ;
53
50
}
54
51
55
- $ templates = $ this ->findTemplatesInDirectory ($ this ->rootDir . ' /Resources/views ' ) ;
52
+ $ templates = null !== $ this ->defaultPath ? $ this -> findTemplatesInDirectory ($ this ->defaultPath , null , [ ' bundles ' ]) : [] ;
56
53
57
- if (null !== $ this ->defaultPath ) {
58
- $ templates = array_merge (
59
- $ templates ,
60
- $ this ->findTemplatesInDirectory ($ this ->defaultPath , null , ['bundles ' ])
61
- );
62
- }
63
54
foreach ($ this ->kernel ->getBundles () as $ bundle ) {
64
55
$ name = $ bundle ->getName ();
65
56
if ('Bundle ' === substr ($ name , -6 )) {
@@ -69,14 +60,8 @@ public function getIterator()
69
60
$ templates = array_merge (
70
61
$ templates ,
71
62
$ 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 ) : []
73
64
);
74
- if (null !== $ this ->defaultPath ) {
75
- $ templates = array_merge (
76
- $ templates ,
77
- $ this ->findTemplatesInDirectory ($ this ->defaultPath .'/bundles/ ' .$ bundle ->getName (), $ name )
78
- );
79
- }
80
65
}
81
66
82
67
foreach ($ this ->paths as $ dir => $ namespace ) {
0 commit comments