File tree Expand file tree Collapse file tree 4 files changed +97
-1
lines changed
Expand file tree Collapse file tree 4 files changed +97
-1
lines changed Original file line number Diff line number Diff line change 2929 "latte/latte" : " ^2.10.0" ,
3030 "nette/http" : " ^3.0.0" ,
3131 "orisai/coding-standard" : " ^2.0.0" ,
32+ "orisai/installer" : " ^1.0.0" ,
3233 "orisai/vfs" : " ^1.0.0" ,
3334 "phpstan/extension-installer" : " ^1.0.0" ,
3435 "phpstan/phpstan" : " ^1.0.0" ,
5758 "allow-plugins" : {
5859 "dealerdirect/phpcodesniffer-composer-installer" : true ,
5960 "infection/extension-installer" : true ,
60- "phpstan/extension-installer" : true
61+ "phpstan/extension-installer" : true ,
62+ "orisai/installer" : true
6163 }
6264 }
6365}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace OriNette \DI \Boot ;
4+
5+ use Orisai \Installer \Loader \BaseLoader ;
6+
7+ final class AutomaticConfigurator extends BaseConfigurator
8+ {
9+
10+ private BaseLoader $ loader ;
11+
12+ public function __construct (string $ rootDir , BaseLoader $ loader )
13+ {
14+ parent ::__construct ($ rootDir );
15+ $ this ->loader = $ loader ;
16+ $ this ->addStaticParameters ([
17+ 'modules ' => $ this ->loader ->loadModulesMeta ($ rootDir ),
18+ ]);
19+ }
20+
21+ protected function loadConfigFiles (): array
22+ {
23+ return $ this ->loader ->loadConfigFiles ($ this ->rootDir );
24+ }
25+
26+ public function loadContainer (): string
27+ {
28+ $ this ->loader ->configureSwitch ('consoleMode ' , $ this ->staticParameters ['consoleMode ' ]);
29+ $ this ->loader ->configureSwitch ('debugMode ' , $ this ->staticParameters ['debugMode ' ]);
30+
31+ return parent ::loadContainer ();
32+ }
33+
34+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ use Orisai \Installer \Schema \ModuleSchema ;
4+
5+ $ schema = new ModuleSchema ();
6+
7+ $ schema ->addSwitch ('consoleMode ' , false );
8+ $ schema ->addSwitch ('debugMode ' , false );
9+
10+ return $ schema ;
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Tests \OriNette \DI \Unit \Boot ;
4+
5+ use OriNette \DI \Boot \AutomaticConfigurator ;
6+ use Orisai \Installer \Loader \DefaultLoader ;
7+ use PHPUnit \Framework \TestCase ;
8+ use function dirname ;
9+ use function mkdir ;
10+ use const PHP_VERSION_ID ;
11+
12+ final class AutomaticConfiguratorTest extends TestCase
13+ {
14+
15+ private string $ rootDir ;
16+
17+ protected function setUp (): void
18+ {
19+ parent ::setUp ();
20+
21+ $ this ->rootDir = dirname (__DIR__ , 3 );
22+ if (PHP_VERSION_ID < 8_01_00 ) {
23+ @mkdir ("$ this ->rootDir /var/build " );
24+ }
25+ }
26+
27+ public function testModules (): void
28+ {
29+ $ configurator = new AutomaticConfigurator ($ this ->rootDir , new DefaultLoader ());
30+ $ configurator ->setForceReloadContainer ();
31+
32+ $ container = $ configurator ->createContainer ();
33+
34+ $ parameters = $ container ->getParameters ();
35+
36+ self ::assertArrayHasKey ('modules ' , $ parameters );
37+ self ::assertSame (
38+ $ parameters ['modules ' ],
39+ [
40+ 'orisai/nette-di ' => [
41+ 'dir ' => $ this ->rootDir ,
42+ ],
43+ '__root__ ' => [
44+ 'dir ' => $ this ->rootDir ,
45+ ],
46+ ],
47+ );
48+ }
49+
50+ }
You can’t perform that action at this time.
0 commit comments