2
2
3
3
declare (strict_types=1 );
4
4
5
- namespace Acme \SyliusExamplePlugin \ Tests \Application ;
5
+ namespace Acme \Tests \ SyliusExamplePlugin \Application ;
6
6
7
7
use PSS \SymfonyMockerContainer \DependencyInjection \MockerContainer ;
8
+ use Sylius \Bundle \CoreBundle \Application \Kernel as SyliusKernel ;
8
9
use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
9
10
use Symfony \Component \Config \Loader \DelegatingLoader ;
10
11
use Symfony \Component \Config \Loader \LoaderInterface ;
19
20
use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
20
21
use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
21
22
use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
23
+ use Symfony \Component \HttpKernel \Bundle \BundleInterface ;
22
24
use Symfony \Component \HttpKernel \Config \FileLocator ;
23
25
use Symfony \Component \HttpKernel \Kernel as BaseKernel ;
24
26
use Symfony \Component \Routing \RouteCollectionBuilder ;
@@ -42,33 +44,29 @@ public function getLogDir(): string
42
44
43
45
public function registerBundles (): iterable
44
46
{
45
- $ contents = require $ this ->getProjectDir () . '/config/bundles.php ' ;
46
- foreach ($ contents as $ class => $ envs ) {
47
- if (isset ($ envs ['all ' ]) || isset ($ envs [$ this ->environment ])) {
48
- yield new $ class ();
49
- }
47
+ foreach ($ this ->getConfigurationDirectories () as $ confDir ) {
48
+ yield from $ this ->registerBundlesFromFile ($ confDir . '/bundles.php ' );
50
49
}
51
50
}
52
51
53
52
protected function configureContainer (ContainerBuilder $ container , LoaderInterface $ loader ): void
54
53
{
55
- $ container ->addResource (new FileResource ($ this ->getProjectDir () . '/config/bundles.php ' ));
54
+ foreach ($ this ->getConfigurationDirectories () as $ confDir ) {
55
+ $ container ->addResource (new FileResource ($ confDir . '/bundles.php ' ));
56
+ }
57
+
56
58
$ container ->setParameter ('container.dumper.inline_class_loader ' , true );
57
- $ confDir = $ this ->getProjectDir () . '/config ' ;
58
59
59
- $ loader ->load ($ confDir . '/{packages}/* ' . self ::CONFIG_EXTS , 'glob ' );
60
- $ loader ->load ($ confDir . '/{packages}/ ' . $ this ->environment . '/**/* ' . self ::CONFIG_EXTS , 'glob ' );
61
- $ loader ->load ($ confDir . '/{services} ' . self ::CONFIG_EXTS , 'glob ' );
62
- $ loader ->load ($ confDir . '/{services}_ ' . $ this ->environment . self ::CONFIG_EXTS , 'glob ' );
60
+ foreach ($ this ->getConfigurationDirectories () as $ confDir ) {
61
+ $ this ->loadContainerConfiguration ($ loader , $ confDir );
62
+ }
63
63
}
64
64
65
65
protected function configureRoutes (RouteCollectionBuilder $ routes ): void
66
66
{
67
- $ confDir = $ this ->getProjectDir () . '/config ' ;
68
-
69
- $ routes ->import ($ confDir . '/{routes}/* ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
70
- $ routes ->import ($ confDir . '/{routes}/ ' . $ this ->environment . '/**/* ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
71
- $ routes ->import ($ confDir . '/{routes} ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
67
+ foreach ($ this ->getConfigurationDirectories () as $ confDir ) {
68
+ $ this ->loadRoutesConfiguration ($ routes , $ confDir );
69
+ }
72
70
}
73
71
74
72
protected function getContainerBaseClass (): string
@@ -80,27 +78,45 @@ protected function getContainerBaseClass(): string
80
78
return parent ::getContainerBaseClass ();
81
79
}
82
80
83
- protected function getContainerLoader ( ContainerInterface $ container ): LoaderInterface
81
+ private function isTestEnvironment ( ): bool
84
82
{
85
- /** @var ContainerBuilder $container */
86
- Assert::isInstanceOf ($ container , ContainerBuilder::class);
87
-
88
- $ locator = new FileLocator ($ this , $ this ->getRootDir () . '/Resources ' );
89
- $ resolver = new LoaderResolver (array (
90
- new XmlFileLoader ($ container , $ locator ),
91
- new YamlFileLoader ($ container , $ locator ),
92
- new IniFileLoader ($ container , $ locator ),
93
- new PhpFileLoader ($ container , $ locator ),
94
- new GlobFileLoader ($ container , $ locator ),
95
- new DirectoryLoader ($ container , $ locator ),
96
- new ClosureLoader ($ container ),
97
- ));
98
-
99
- return new DelegatingLoader ($ resolver );
83
+ return 0 === strpos ($ this ->getEnvironment (), 'test ' );
100
84
}
101
85
102
- private function isTestEnvironment ( ): bool
86
+ private function loadContainerConfiguration ( LoaderInterface $ loader , string $ confDir ): void
103
87
{
104
- return 0 === strpos ($ this ->getEnvironment (), 'test ' );
88
+ $ loader ->load ($ confDir . '/{packages}/* ' . self ::CONFIG_EXTS , 'glob ' );
89
+ $ loader ->load ($ confDir . '/{packages}/ ' . $ this ->environment . '/**/* ' . self ::CONFIG_EXTS , 'glob ' );
90
+ $ loader ->load ($ confDir . '/{services} ' . self ::CONFIG_EXTS , 'glob ' );
91
+ $ loader ->load ($ confDir . '/{services}_ ' . $ this ->environment . self ::CONFIG_EXTS , 'glob ' );
92
+ }
93
+
94
+ private function loadRoutesConfiguration (RouteCollectionBuilder $ routes , string $ confDir ): void
95
+ {
96
+ $ routes ->import ($ confDir . '/{routes}/* ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
97
+ $ routes ->import ($ confDir . '/{routes}/ ' . $ this ->environment . '/**/* ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
98
+ $ routes ->import ($ confDir . '/{routes} ' . self ::CONFIG_EXTS , '/ ' , 'glob ' );
99
+ }
100
+
101
+ /**
102
+ * @return BundleInterface[]
103
+ */
104
+ private function registerBundlesFromFile (string $ bundlesFile ): iterable
105
+ {
106
+ $ contents = require $ bundlesFile ;
107
+ foreach ($ contents as $ class => $ envs ) {
108
+ if (isset ($ envs ['all ' ]) || isset ($ envs [$ this ->environment ])) {
109
+ yield new $ class ();
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @return string[]
116
+ */
117
+ private function getConfigurationDirectories (): iterable
118
+ {
119
+ yield $ this ->getProjectDir () . '/config ' ;
120
+ yield $ this ->getProjectDir () . '/config/sylius/ ' . SyliusKernel::MAJOR_VERSION . '. ' . SyliusKernel::MINOR_VERSION ;
105
121
}
106
122
}
0 commit comments