@@ -69,26 +69,13 @@ public function load(array $configs, ContainerBuilder $container)
69
69
}
70
70
71
71
// register bundles as Twig namespaces
72
- $ bundles = $ this ->getBundlesByChildPriority ($ container );
73
- foreach ($ bundles as $ bundle => $ bundleReflection ) {
74
- /** @var \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundleInstance */
75
- $ bundleInstance = $ bundleReflection ->newInstance ();
76
-
77
- if (null !== $ parentBundle = $ bundleInstance ->getParent ()) {
78
- if (is_dir ($ dir = $ container ->getParameter ('kernel.root_dir ' ).'/Resources/ ' .$ bundle .'/views ' )) {
79
- $ this ->addTwigPath ($ twigFilesystemLoaderDefinition , $ dir , $ parentBundle );
80
- }
81
-
82
- if (is_dir ($ dir = $ bundleInstance ->getPath ().'/Resources/views ' )) {
83
- $ this ->addTwigPath ($ twigFilesystemLoaderDefinition , $ dir , $ parentBundle );
84
- }
85
- }
86
-
72
+ foreach ($ container ->getParameter ('kernel.bundles ' ) as $ bundle => $ class ) {
87
73
if (is_dir ($ dir = $ container ->getParameter ('kernel.root_dir ' ).'/Resources/ ' .$ bundle .'/views ' )) {
88
74
$ this ->addTwigPath ($ twigFilesystemLoaderDefinition , $ dir , $ bundle );
89
75
}
90
76
91
- if (is_dir ($ dir = $ bundleInstance ->getPath ().'/Resources/views ' )) {
77
+ $ reflection = new \ReflectionClass ($ class );
78
+ if (is_dir ($ dir = dirname ($ reflection ->getFilename ()).'/Resources/views ' )) {
92
79
$ this ->addTwigPath ($ twigFilesystemLoaderDefinition , $ dir , $ bundle );
93
80
}
94
81
}
@@ -143,36 +130,12 @@ public function load(array $configs, ContainerBuilder $container)
143
130
));
144
131
}
145
132
146
- /**
147
- * @param ContainerBuilder $container
148
- * @return array | \ReflectionClass[]
149
- */
150
- private function getBundlesByChildPriority (ContainerBuilder $ container )
151
- {
152
- $ childBundles = array ();
153
- $ parentBundles = array ();
154
-
155
- foreach ($ container ->getParameter ('kernel.bundles ' ) as $ bundle => $ class ) {
156
- $ reflection = new \ReflectionClass ($ class );
157
-
158
- $ bundleInstance = $ reflection ->newInstance ();
159
- if (null === $ bundleInstance ->getParent ()) {
160
- $ parentBundles [$ bundle ] = $ reflection ;
161
- } else {
162
- $ childBundles [$ bundle ] = $ reflection ;
163
- }
164
- }
165
-
166
- return array_merge ($ childBundles , $ parentBundles );
167
- }
168
-
169
133
private function addTwigPath ($ twigFilesystemLoaderDefinition , $ dir , $ bundle )
170
134
{
171
135
$ name = $ bundle ;
172
136
if ('Bundle ' === substr ($ name , -6 )) {
173
137
$ name = substr ($ name , 0 , -6 );
174
138
}
175
-
176
139
$ twigFilesystemLoaderDefinition ->addMethodCall ('addPath ' , array ($ dir , $ name ));
177
140
}
178
141
0 commit comments