Skip to content
Permalink
Browse files

ExtensionsExtension: added extension type checking (#209)

  • Loading branch information...
janbarasek authored and dg committed Jul 19, 2019
1 parent 1a47803 commit a49bf895da312cc6a8369a37c102480a4b6cabcb
Showing with 26 additions and 4 deletions.
  1. +6 −4 src/DI/Extensions/ExtensionsExtension.php
  2. +20 −0 tests/DI/ExtensionsExtension.error.phpt
@@ -29,12 +29,14 @@ public function loadConfiguration()
if (is_int($name)) {
$name = null;
}
$args = [];
if ($class instanceof Nette\DI\Definitions\Statement) {
$rc = new \ReflectionClass($class->getEntity());
$this->compiler->addExtension($name, $rc->newInstanceArgs($class->arguments));
} else {
$this->compiler->addExtension($name, new $class);
[$class, $args] = [$class->getEntity(), $class->arguments];
}
if (!is_a($class, Nette\DI\CompilerExtension::class, true)) {
throw new Nette\DI\InvalidConfigurationException("Extension should be Nette\\DI\\CompilerExtension, '$class' given.");
}
$this->compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args));
}
}
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
use Nette\DI;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$compiler = new DI\Compiler;
$compiler->addExtension('extensions', new Nette\DI\Extensions\ExtensionsExtension);
Assert::exception(function () use ($compiler) {
createContainer($compiler, '
extensions:
foo: stdClass
');
}, Nette\DI\InvalidConfigurationException::class, "Extension should be Nette\\DI\\CompilerExtension, 'stdClass' given.");

0 comments on commit a49bf89

Please sign in to comment.
You can’t perform that action at this time.