| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This file is part of the Nette Framework (https://nette.org) |
| 5 |
* Copyright (c) 2004 David Grudl (https://davidgrudl.com) |
| 6 |
*/ |
| 7 |
declare (strict_types=1); |
| 8 |
namespace Packetery\Nette\DI\Extensions; |
| 9 |
|
| 10 |
use Packetery\Nette; |
| 11 |
/** |
| 12 |
* Enables registration of other extensions in $config file |
| 13 |
*/ |
| 14 |
class ExtensionsExtension extends \Packetery\Nette\DI\CompilerExtension |
| 15 |
{ |
| 16 |
public function getConfigSchema() : \Packetery\Nette\Schema\Schema |
| 17 |
{ |
| 18 |
return \Packetery\Nette\Schema\Expect::arrayOf('string|\\Packetery\\Nette\\DI\\Definitions\\Statement'); |
| 19 |
} |
| 20 |
public function loadConfiguration() |
| 21 |
{ |
| 22 |
foreach ($this->getConfig() as $name => $class) { |
| 23 |
if (\is_int($name)) { |
| 24 |
$name = null; |
| 25 |
} |
| 26 |
$args = []; |
| 27 |
if ($class instanceof \Packetery\Nette\DI\Definitions\Statement) { |
| 28 |
[$class, $args] = [$class->getEntity(), $class->arguments]; |
| 29 |
} |
| 30 |
if (!\is_a($class, \Packetery\Nette\DI\CompilerExtension::class, \true)) { |
| 31 |
throw new \Packetery\Nette\DI\InvalidConfigurationException(\sprintf("Extension '%s' not found or is not \\Packetery\\Nette\\DI\\CompilerExtension descendant.", $class)); |
| 32 |
} |
| 33 |
$this->compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args)); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|