Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/route-factory-prototypes' of https://github.com/…
Browse files Browse the repository at this point in the history
…weierophinney/zf2 into pull/4622
  • Loading branch information
DASPRiD committed Jun 11, 2013
2 parents bb5ec1d + 32333f8 commit 6efbd82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
7 changes: 4 additions & 3 deletions library/Zend/Mvc/Router/SimpleRouteStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ public static function factory($options = array())
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
}

$instance = new static();

$routePluginManager = null;
if (isset($options['route_plugins'])) {
$instance->setRoutePluginManager($options['route_plugins']);
$routePluginManager = $options['route_plugins'];
}

$instance = new static($routePluginManager);

if (isset($options['routes'])) {
$instance->addRoutes($options['routes']);
}
Expand Down
31 changes: 13 additions & 18 deletions library/Zend/Mvc/Service/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,33 @@ class RouterFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
$config = $serviceLocator->get('Config');
$routerConfig = array();
$routePluginManager = $serviceLocator->get('RoutePluginManager');

if (
$rName === 'ConsoleRouter' || // force console router
($cName === 'router' && Console::isConsole()) // auto detect console
if ($rName === 'ConsoleRouter' // force console router
|| ($cName === 'router' && Console::isConsole()) // auto detect console
) {
// We are in a console, use console router.
if (isset($config['console']) && isset($config['console']['router'])) {
$routerConfig = $config['console']['router'];
} else {
$routerConfig = array();
}

$router = new ConsoleRouter($routePluginManager);
} else {
// This is an HTTP request, so use HTTP router
$router = new HttpRouter($routePluginManager);
$routerConfig = isset($config['router']) ? $config['router'] : array();
}
if (!isset($routerConfig['route_plugins'])) {
$routerConfig['route_plugins'] = $routePluginManager;
}

if (isset($routerConfig['route_plugins'])) {
$router->setRoutePluginManager($routerConfig['route_plugins']);
return ConsoleRouter::factory($routerConfig);
}

if (isset($routerConfig['routes'])) {
$router->addRoutes($routerConfig['routes']);
// This is an HTTP request, so use HTTP router
if (isset($config['router'])) {
$routerConfig = $config['router'];
}

if (isset($routerConfig['default_params'])) {
$router->setDefaultParams($routerConfig['default_params']);
if (!isset($routerConfig['route_plugins'])) {
$routerConfig['route_plugins'] = $routePluginManager;
}

return $router;
return HttpRouter::factory($routerConfig);
}
}

0 comments on commit 6efbd82

Please sign in to comment.