Skip to content

Commit

Permalink
RoutingExtension: creates service 'routes' only when routes are defin…
Browse files Browse the repository at this point in the history
…ed (BC break)
  • Loading branch information
dg committed Jul 12, 2020
1 parent 0ef0688 commit 2c9e9d2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Bridges/ApplicationDI/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ public function __construct(bool $debugMode = false)

public function loadConfiguration()
{
if (!$this->config->routes) {
return;
}

$builder = $this->getContainerBuilder();

$router = $builder->addDefinition($this->prefix('router'))
->setType(Nette\Routing\Router::class)
->setFactory(Nette\Application\Routers\RouteList::class);

if ($this->config->routeClass) {
Expand Down Expand Up @@ -80,13 +83,20 @@ public function beforeCompile()
new Definitions\Statement(Nette\Bridges\ApplicationTracy\RoutingPanel::class),
]);
}

if (!$builder->getByType(Nette\Routing\Router::class)) {
$builder->addDefinition($this->prefix('router'))
->setFactory(Nette\Routing\SimpleRouter::class);
}
}


public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
if ($this->config->cache) {
$method = $class->getMethod(Nette\DI\Container::getMethodName($this->prefix('router')));
$builder = $this->getContainerBuilder();
$def = $builder->getDefinitionByType(Nette\Routing\Router::class);
$method = $class->getMethod(Nette\DI\Container::getMethodName($def->getName()));
try {
$router = eval($method->getBody());
if ($router instanceof Nette\Application\Routers\RouteList) {
Expand Down

0 comments on commit 2c9e9d2

Please sign in to comment.