@@ -25,17 +25,20 @@ class TemplateIterator implements \IteratorAggregate
25
25
private $ rootDir ;
26
26
private $ templates ;
27
27
private $ paths ;
28
+ private $ defaultPath ;
28
29
29
30
/**
30
- * @param KernelInterface $kernel A KernelInterface instance
31
- * @param string $rootDir The directory where global templates can be stored
32
- * @param array $paths Additional Twig paths to warm
31
+ * @param KernelInterface $kernel A KernelInterface instance
32
+ * @param string $rootDir The directory where global templates can be stored
33
+ * @param array $paths Additional Twig paths to warm
34
+ * @param string $defaultPath The directory where global templates can be stored
33
35
*/
34
- public function __construct (KernelInterface $ kernel , $ rootDir , array $ paths = array ())
36
+ public function __construct (KernelInterface $ kernel , $ rootDir , array $ paths = array (), $ defaultPath = null )
35
37
{
36
38
$ this ->kernel = $ kernel ;
37
39
$ this ->rootDir = $ rootDir ;
38
40
$ this ->paths = $ paths ;
41
+ $ this ->defaultPath = $ defaultPath ;
39
42
}
40
43
41
44
/**
@@ -47,7 +50,10 @@ public function getIterator()
47
50
return $ this ->templates ;
48
51
}
49
52
50
- $ this ->templates = $ this ->findTemplatesInDirectory ($ this ->rootDir .'/Resources/views ' );
53
+ $ this ->templates = array_merge (
54
+ $ this ->findTemplatesInDirectory ($ this ->rootDir .'/Resources/views ' ),
55
+ $ this ->findTemplatesInDirectory ($ this ->defaultPath , null , array ('bundles ' ))
56
+ );
51
57
foreach ($ this ->kernel ->getBundles () as $ bundle ) {
52
58
$ name = $ bundle ->getName ();
53
59
if ('Bundle ' === substr ($ name , -6 )) {
@@ -57,7 +63,8 @@ public function getIterator()
57
63
$ this ->templates = array_merge (
58
64
$ this ->templates ,
59
65
$ this ->findTemplatesInDirectory ($ bundle ->getPath ().'/Resources/views ' , $ name ),
60
- $ this ->findTemplatesInDirectory ($ this ->rootDir .'/ ' .$ bundle ->getName ().'/views ' , $ name )
66
+ $ this ->findTemplatesInDirectory ($ this ->rootDir .'/ ' .$ bundle ->getName ().'/views ' , $ name ),
67
+ $ this ->findTemplatesInDirectory ($ this ->defaultPath .'/bundles/ ' .$ bundle ->getName (), $ name )
61
68
);
62
69
}
63
70
@@ -76,14 +83,14 @@ public function getIterator()
76
83
*
77
84
* @return array
78
85
*/
79
- private function findTemplatesInDirectory ($ dir , $ namespace = null )
86
+ private function findTemplatesInDirectory ($ dir , $ namespace = null , array $ excludeDirs = array () )
80
87
{
81
88
if (!is_dir ($ dir )) {
82
89
return array ();
83
90
}
84
91
85
92
$ templates = array ();
86
- foreach (Finder::create ()->files ()->followLinks ()->in ($ dir ) as $ file ) {
93
+ foreach (Finder::create ()->files ()->followLinks ()->in ($ dir )-> exclude ( $ excludeDirs ) as $ file ) {
87
94
$ templates [] = (null !== $ namespace ? '@ ' .$ namespace .'/ ' : '' ).str_replace ('\\' , '/ ' , $ file ->getRelativePathname ());
88
95
}
89
96
0 commit comments