Kdyby/Framework — Issue #14: Application is inconfigurable through config.neon
Author: gmvasek
Created: 2012-02-08 20:48:16+00:00
State: open

Líbí se mi způsob použití Application v bootstrapu, takže se "inspiruju"... narazil jsem na problém - při použití injectu samotné Application do DI kontejneru neproběhne jakékoliv nastavení použité v config.neon, takže se nezaregistrují debug bar panely a nenastaví se případné catchExceptions / errorPresenter. Zatím to řeším takhle, ale nelíbí se mi to:

// Application.php
self::$instance = $this;
$container = $this->configurator->getContainer();
$container->addService('application', $this);
$container->avalon->createApplication();

// CompilerExtension
$application = $container->addDefinition($this->prefix('application'))
->setClass('Avalon\Application\Application')
->setFactory('Avalon\Application\Application::getInstance')
->setShared(FALSE);

$application->setup = $container->getDefinition('application')->setup;

Výsledný SystemContainer to vygeneruje cca takovýto (stejné setupy u createServiceApplication i mé vlastní továrničky):

/**
* @return Nette\Application\Application
*/
protected function createServiceApplication()
{
$service = new Nette\Application\Application($this->{'nette.presenterFactory'}, $this->router, $this->httpRequest, $this->httpResponse);
$service->catchExceptions = FALSE;
$service->errorPresenter = NULL;
Nette\Application\Diagnostics\RoutingPanel::initializePanel($service);
Nette\Diagnostics\Debugger::$bar->addPanel(new Nette\Application\Diagnostics\RoutingPanel($this->router, $this->httpRequest));
return $service;
}

/**
* @return Avalon\Application\Application
*/
public function createAvalon_application()
{
$service = Avalon\Application\Application::getInstance();
if (!$service instanceof Avalon\Application\Application) {
throw new Nette\UnexpectedValueException('Unable to create service \'avalon.applicationConfiguration\', value returned by factory is not Avalon\\Application\\Application type.');
}
$service->catchExceptions = FALSE;
$service->errorPresenter = NULL;
Nette\Application\Diagnostics\RoutingPanel::initializePanel($this->application);
Nette\Diagnostics\Debugger::$bar->addPanel(new Nette\Application\Diagnostics\RoutingPanel($this->router, $this->httpRequest));
return $service;
}