Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow to pull route manager from sl

  • Loading branch information...
commit 3e40f72bfed74d4b2c9c2da5f975db1460f92bad 1 parent dcc3c04
@bakura10 authored
View
21 library/Zend/ModuleManager/Feature/RouteProviderInterface.php
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace Zend\ModuleManager\Feature;
+
+interface RouteProviderInterface
+{
+ /**
+ * Expected to return \Zend\ServiceManager\Config object or array to
+ * seed such an object.
+ *
+ * @return array|\Zend\ServiceManager\Config
+ */
+ public function getRouteConfig();
+}
View
13 library/Zend/Mvc/Router/SimpleRouteStack.php
@@ -41,11 +41,18 @@ class SimpleRouteStack implements RouteStackInterface
/**
* Create a new simple route stack.
+ *
+ * @param RoutePluginManager $routePluginManager
*/
- public function __construct()
+ public function __construct(RoutePluginManager $routePluginManager = null)
{
- $this->routes = new PriorityList();
- $this->routePluginManager = new RoutePluginManager();
+ $this->routes = new PriorityList();
+
+ if ($routePluginManager === null) {
+ $routePluginManager = new RoutePluginManager();
+ }
+
+ $this->routePluginManager = $routePluginManager;
$this->init();
}
View
6 library/Zend/Mvc/Service/ModuleManagerFactory.php
@@ -85,6 +85,12 @@ public function createService(ServiceLocatorInterface $serviceLocator)
'Zend\ModuleManager\Feature\FormElementProviderInterface',
'getFormElementConfig'
);
+ $serviceListener->addServiceManager(
+ 'RoutePluginManager',
+ 'routes',
+ 'Zend\ModuleManager\Feature\RouteProviderInterface',
+ 'getRouteConfig'
+ );
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
View
15 library/Zend/Mvc/Service/RoutePluginManagerFactory.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace Zend\Mvc\Service;
+
+class RoutePluginManagerFactory extends AbstractPluginManagerFactory
+{
+ const PLUGIN_MANAGER_CLASS = 'Zend\Mvc\Router\RoutePluginManager';
+}
View
24 library/Zend/Mvc/Service/RouterFactory.php
@@ -25,13 +25,14 @@ class RouterFactory implements FactoryInterface
* default.
*
* @param ServiceLocatorInterface $serviceLocator
- * @param string|null $cName
- * @param string|null $rName
+ * @param string|null $cName
+ * @param string|null $rName
* @return \Zend\Mvc\Router\RouteStackInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
- $config = $serviceLocator->get('Config');
+ $config = $serviceLocator->get('Config');
+ $routePluginManager = $serviceLocator->get('RoutePluginManager');
if (
$rName === 'ConsoleRouter' || // force console router
@@ -44,12 +45,25 @@ public function createService(ServiceLocatorInterface $serviceLocator, $cName =
$routerConfig = array();
}
- $router = ConsoleRouter::factory($routerConfig);
+ $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();
- $router = HttpRouter::factory($routerConfig);
}
+
+ if (isset($routerConfig['route_plugins'])) {
+ $router->setRoutePluginManager($routerConfig['route_plugins']);
+ }
+
+ if (isset($routerConfig['routes'])) {
+ $router->addRoutes($routerConfig['routes']);
+ }
+
+ if (isset($routerConfig['default_params'])) {
+ $router->setDefaultParams($routerConfig['default_params']);
+ }
+
return $router;
}
}
View
1  library/Zend/Mvc/Service/ServiceListenerFactory.php
@@ -57,6 +57,7 @@ class ServiceListenerFactory implements FactoryInterface
'Request' => 'Zend\Mvc\Service\RequestFactory',
'Response' => 'Zend\Mvc\Service\ResponseFactory',
'Router' => 'Zend\Mvc\Service\RouterFactory',
+ 'RoutePluginManager' => 'Zend\Mvc\Service\RoutePluginManagerFactory',
'ValidatorManager' => 'Zend\Mvc\Service\ValidatorManagerFactory',
'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
'ViewFeedRenderer' => 'Zend\Mvc\Service\ViewFeedRendererFactory',
View
1  tests/ZendTest/Mvc/ApplicationTest.php
@@ -76,6 +76,7 @@ public function setUp()
'factories' => array(
'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
+ 'RoutePluginManager' => 'Zend\Mvc\Service\RoutePluginManagerFactory',
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
'Config' => $config,
View
1  tests/ZendTest/Mvc/DispatchListenerTest.php
@@ -66,6 +66,7 @@ public function setUp()
'factories' => array(
'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
+ 'RoutePluginManager' => 'Zend\Mvc\Service\RoutePluginManagerFactory',
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
'HttpRouter' => 'Zend\Mvc\Service\RouterFactory',
'Config' => $config,
View
9 tests/ZendTest/Mvc/Router/RoutePluginManagerTest.php
@@ -27,4 +27,13 @@ public function testLoadNonExistentRoute()
$this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException');
$routes->get('foo');
}
+
+ public function testCanLoadAnyRoute()
+ {
+ $routes = new RoutePluginManager();
+ $routes->setInvokableClass('DummyRoute', 'ZendTest\Mvc\Router\TestAsset\DummyRoute');
+ $route = $routes->get('DummyRoute');
+
+ $this->assertInstanceOf('ZendTest\Mvc\Router\TestAsset\DummyRoute', $route);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.