@@ -82,28 +82,26 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
8282 }
8383 }
8484 });
85-
8685 }
86+
8787 public function registerBundles (): iterable
8888 {
89+ $ env = $ this ->getEnvironment ();
90+
8991 if (!is_file ($ bundlesPath = $ this ->getBundlesPath ())) {
9092 yield new FrameworkBundle ();
91-
9293 return ;
9394 }
9495
95- $ contents = require $ bundlesPath ;
96+ $ contents = $ this ->loadMainBundles ($ bundlesPath );
97+ $ additionalBundlesLoaded = $ this ->loadAdditionalBundlesFromEnv ($ contents );
9698
97- if (isset ($ _SERVER ['BUNDLES_TO_ENABLE ' ])) {
98- foreach (explode ('; ' , $ _SERVER ['BUNDLES_TO_ENABLE ' ]) as $ bundleClass ) {
99- if (class_exists ($ bundleClass )) {
100- $ contents [$ bundleClass ] = ['all ' => true ];
101- }
102- }
99+ if (!$ additionalBundlesLoaded ) {
100+ $ this ->loadBundlesToEnable ($ contents );
103101 }
104102
105103 foreach ($ contents as $ class => $ envs ) {
106- if ($ envs [$ this -> environment ] ?? $ envs ['all ' ] ?? false ) {
104+ if ($ envs [$ env ] ?? $ envs ['all ' ] ?? false ) {
107105 yield new $ class ();
108106 }
109107 }
@@ -139,4 +137,49 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
139137
140138 return $ collection ;
141139 }
140+
141+ private function loadMainBundles (string $ path ): array
142+ {
143+ return require $ path ;
144+ }
145+
146+ private function loadAdditionalBundlesFromEnv (array &$ contents ): bool
147+ {
148+ if (!isset ($ _SERVER ['TEST_APP_BUNDLES_PATH ' ])) {
149+ return false ;
150+ }
151+
152+ $ relativePath = $ _SERVER ['TEST_APP_BUNDLES_PATH ' ];
153+ $ absolutePath = \dirname ($ this ->getProjectDir (), 3 ) . '/ ' . ltrim ($ relativePath , '/ ' );
154+
155+ if (!is_file ($ absolutePath )) {
156+ return false ;
157+ }
158+
159+ $ additionalBundles = require $ absolutePath ;
160+ if (!\is_array ($ additionalBundles )) {
161+ return false ;
162+ }
163+
164+ foreach ($ additionalBundles as $ bundleClass => $ envs ) {
165+ if (\class_exists ($ bundleClass )) {
166+ $ contents [$ bundleClass ] = $ envs ;
167+ }
168+ }
169+
170+ return true ;
171+ }
172+
173+ private function loadBundlesToEnable (array &$ contents ): void
174+ {
175+ if (!isset ($ _SERVER ['BUNDLES_TO_ENABLE ' ])) {
176+ return ;
177+ }
178+
179+ foreach (explode ('; ' , $ _SERVER ['BUNDLES_TO_ENABLE ' ]) as $ bundleClass ) {
180+ if (\class_exists ($ bundleClass )) {
181+ $ contents [$ bundleClass ] = ['all ' => true ];
182+ }
183+ }
184+ }
142185}
0 commit comments