3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mvc\Router\Console
;
13 use Zend\Mvc\Router\Exception
;
14 use Zend\Mvc\Router\RouteInvokableFactory
;
15 use Zend\Mvc\Router\SimpleRouteStack
as BaseSimpleRouteStack
;
16 use Zend\ServiceManager\Config
;
17 use Zend\Stdlib\ArrayUtils
;
20 * Tree search implementation.
22 class SimpleRouteStack
extends BaseSimpleRouteStack
25 * init(): defined by SimpleRouteStack.
27 * @see BaseSimpleRouteStack::init()
29 protected function init()
33 'catchall' => Catchall
::class,
34 'catchAll' => Catchall
::class,
35 'Catchall' => Catchall
::class,
36 'CatchAll' => Catchall
::class,
37 'simple' => Simple
::class,
38 'Simple' => Simple
::class,
41 Catchall
::class => RouteInvokableFactory
::class,
42 Simple
::class => RouteInvokableFactory
::class,
44 // v2 normalized names
45 'zendmvcrouterconsolecatchall' => RouteInvokableFactory
::class,
46 'zendmvcrouterconsolesimple' => RouteInvokableFactory
::class,
48 ]))->configureServiceManager($this->routePluginManager
);
52 * addRoute(): defined by RouteStackInterface interface.
54 * @see RouteStackInterface::addRoute()
57 * @param int $priority
58 * @return SimpleRouteStack
60 public function addRoute($name, $route, $priority = null)
62 if (!$route instanceof RouteInterface
) {
63 $route = $this->routeFromArray($route);
66 return parent
::addRoute($name, $route, $priority);
70 * routeFromArray(): defined by SimpleRouteStack.
72 * @see BaseSimpleRouteStack::routeFromArray()
73 * @param array|Traversable $specs
74 * @return RouteInterface
75 * @throws Exception\InvalidArgumentException
76 * @throws Exception\RuntimeException
78 protected function routeFromArray($specs)
80 if ($specs instanceof Traversable
) {
81 $specs = ArrayUtils
::iteratorToArray($specs);
84 if (! is_array($specs)) {
85 throw new Exception\
InvalidArgumentException('Route definition must be an array or Traversable object');
88 // default to 'simple' console route
89 if (! isset($specs['type'])) {
90 $specs['type'] = Simple
::class;
94 $route = parent
::routeFromArray($specs);
96 if (! $route instanceof RouteInterface
) {
97 throw new Exception\
RuntimeException('Given route does not implement Console route interface');