Konfigurace extensions z jiné extension

CzeM
Člen | 9
+
0
-

Ahoj,

dokázal by někdo podadit jak správně na konfiguraci extensions z jiné extension?

Mám core vlastního řešení jako extension, ve kterém bych rád nastavil vše ostatní (další extensions, services, parameters a samozřejmě samotnou konfiguraci těchto jiných rozšíření).

Děkuji

Felix
Nette Core | 1196
+
0
-

Ahoj. Rad poradim, ukazes alespon pseudokod jak si to predstavujes?

MajklNajt
Člen | 494
+
0
-

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
+
+2
-

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.