Skip to content

Commit

Permalink
CliRouter: fixed prepending
Browse files Browse the repository at this point in the history
  • Loading branch information
grongor authored and fprochazka committed Aug 9, 2013
1 parent 3c2fd11 commit 119b68e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/Kdyby/Console/CliRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,30 @@ public function constructUrl(Request $appRequest, Nette\Http\Url $refUrl)

/**
* @param \Nette\Application\IRouter $router
* @param \Nette\DI\Container $container
* @param CliRouter $cliRouter
* @throws \Nette\Utils\AssertionException
* @return \Nette\Application\Routers\RouteList
*/
public static function prependTo(Nette\Application\IRouter $router, Nette\DI\Container $container)
public static function prependTo(Nette\Application\IRouter &$router, self $cliRouter)
{
$routes = new RouteList();
$routes[] = new static($container);
$routes[] = $router;
return $routes;
if (!$router instanceof RouteList) {
throw new Nette\Utils\AssertionException(
'If you want to use Kdyby/Console then your main router ' .
'must be an instance of Nette\Application\Routers\RouteList'
);
}

$router[] = $cliRouter; // need to increase the array size

$lastKey = count($router) - 1;
foreach ($router as $i => $route) {
if ($i === $lastKey) {
break;
}
$router[$i + 1] = $route;
}

$router[0] = $cliRouter;
}

}
2 changes: 1 addition & 1 deletion src/Kdyby/Console/DI/ConsoleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function loadConfiguration()
->setAutowired(FALSE);

$builder->getDefinition('router')
->addSetup('$service = Kdyby\Console\CliRouter::prependTo($service, ?)', array('@container'));
->addSetup('Kdyby\Console\CliRouter::prependTo($service, ?)', array($this->prefix('@router')));

$builder->getDefinition('nette.presenterFactory')
->addSetup('if (method_exists($service, ?)) { $service->setMapping(array(? => ?)); } ' .
Expand Down

0 comments on commit 119b68e

Please sign in to comment.