Skip to content

Commit

Permalink
orisai/installer support
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Oct 2, 2022
1 parent 0495661 commit 65fcfc8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"latte/latte": "^2.10.0",
"nette/http": "^3.0.0",
"orisai/coding-standard": "^2.0.0",
"orisai/installer": "^1.0.0",
"orisai/vfs": "^1.0.0",
"phpstan/extension-installer": "^1.0.0",
"phpstan/phpstan": "^1.0.0",
Expand Down Expand Up @@ -57,7 +58,8 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"orisai/installer": true
}
}
}
34 changes: 34 additions & 0 deletions src/Boot/AutomaticConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

namespace OriNette\DI\Boot;

use Orisai\Installer\Loader\BaseLoader;

final class AutomaticConfigurator extends BaseConfigurator
{

private BaseLoader $loader;

public function __construct(string $rootDir, BaseLoader $loader)
{
parent::__construct($rootDir);
$this->loader = $loader;
$this->addStaticParameters([
'modules' => $this->loader->loadModulesMeta($rootDir),
]);
}

protected function loadConfigFiles(): array
{
return $this->loader->loadConfigFiles($this->rootDir);
}

public function loadContainer(): string
{
$this->loader->configureSwitch('consoleMode', $this->staticParameters['consoleMode']);
$this->loader->configureSwitch('debugMode', $this->staticParameters['debugMode']);

return parent::loadContainer();
}

}
10 changes: 10 additions & 0 deletions src/Orisai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

use Orisai\Installer\Schema\ModuleSchema;

$schema = new ModuleSchema();

$schema->addSwitch('consoleMode', false);
$schema->addSwitch('debugMode', false);

return $schema;
50 changes: 50 additions & 0 deletions tests/Unit/Boot/AutomaticConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types = 1);

namespace Tests\OriNette\DI\Unit\Boot;

use OriNette\DI\Boot\AutomaticConfigurator;
use Orisai\Installer\Loader\DefaultLoader;
use PHPUnit\Framework\TestCase;
use function dirname;
use function mkdir;
use const PHP_VERSION_ID;

final class AutomaticConfiguratorTest extends TestCase
{

private string $rootDir;

protected function setUp(): void
{
parent::setUp();

$this->rootDir = dirname(__DIR__, 3);
if (PHP_VERSION_ID < 8_01_00) {
@mkdir("$this->rootDir/var/build");
}
}

public function testModules(): void
{
$configurator = new AutomaticConfigurator($this->rootDir, new DefaultLoader());
$configurator->setForceReloadContainer();

$container = $configurator->createContainer();

$parameters = $container->getParameters();

self::assertArrayHasKey('modules', $parameters);
self::assertSame(
$parameters['modules'],
[
'orisai/nette-di' => [
'dir' => $this->rootDir,
],
'__root__' => [
'dir' => $this->rootDir,
],
],
);
}

}

0 comments on commit 65fcfc8

Please sign in to comment.