Konfigurace extensions z jiné extension
- MajklNajt
- Člen | 494
ahoj @Felix, doriešili ste to nejako? snažím sa totiž tiež
registrovať extensions vo vlastnej extension, a padá mi to do
Nette\DeprecatedException
(Extensions … were added while
container was being compiled.)
registrujem to takto:
class CoreExtension extends CompilerExtension
{
public function getConfigSchema(): Schema
{
return Expect::structure([
"console" => Expect::structure([
"mode" => Expect::bool(false),
"wwwDir" => Expect::string(),
]),
"dbal" => Expect::structure([
"host" => Expect::string(),
"user" => Expect::string(),
"password" => Expect::string()->nullable(),
"name" => Expect::string(),
]),
"orm" => Expect::structure([
"autoGenerateProxyClasses" => Expect::bool(true),
]),
]);
}
public function loadConfiguration(): void
{
$this->addConsole();
$this->addNettrine();
}
private function addConsole(): void
{
$extension = new ConsoleExtension($this->config->console->mode);
$this->compiler->addExtension("console", $extension);
}
private function addNettrine(): void
{
$cache = new CacheExtension();
$this->compiler->addExtension("nettrine.cache", $cache);
$dbal = new DbalExtension();
$dbal->setConfig([
"connection" => [
"driver" => "pdo_mysql",
"charset" => "UTF8",
"host" => $this->config->dbal->host,
"user" => $this->config->dbal->user,
"password" => $this->config->dbal->password,
"dbname" => $this->config->dbal->name,
],
]);
$this->compiler->addExtension("nettrine.dbal", $dbal);
$dbalConsole = new DbalConsoleExtension($this->config->console->mode);
$this->compiler->addExtension("nettrine.dbal.console", $dbalConsole);
$orm = new OrmExtension();
$orm->setConfig([
"configuration" => [
"autoGenerateProxyClasses" => $this->config->orm->autoGenerateProxyClasses,
],
]);
$this->compiler->addExtension("nettrine.orm", $orm);
$ormCache = new OrmCacheExtension();
$ormCache->setConfig([
"defaultDriver" => "Doctrine\Common\Cache\ArrayCache",
"queryCache" => "Doctrine\Common\Cache\ArrayCache",
"resultCache" => "Doctrine\Common\Cache\ArrayCache",
"hydrationCache" => "Doctrine\Common\Cache\ArrayCache",
"metadataCache" => "Doctrine\Common\Cache\ArrayCache",
]);
$this->compiler->addExtension("nettrine.orm.cache", $ormCache);
$ormConsole = new OrmConsoleExtension($this->config->console->mode);
$this->compiler->addExtension("nettrine.orm.console", $ormConsole);
$ormAttributes = new OrmAttributesExtension();
$ormAttributes->setConfig([
"mapping" => [],
]);
$this->compiler->addExtension("nettrine.orm.attributes", $ormAttributes);
}
}
Editoval MajklNajt (6. 9. 18:25)
- Marek Bartoš
- Nette Blogger | 1261
Tenhle přístup nikdy nefungoval moc dobře, nesnaž se o to. Není nic snazšího, než mít konfigurační neon i ve vendoru a v boostrapu ho přidat jako jakýkoli jiný. Extensions si můžeš zaregistrovat v něm.