Skip to content

Commit 65fcfc8

Browse files
committed
orisai/installer support
1 parent 0495661 commit 65fcfc8

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
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",
@@ -57,7 +58,8 @@
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
}

src/Boot/AutomaticConfigurator.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

src/Orisai.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

0 commit comments

Comments
 (0)