45f0a2d110ce20eb986bd09077fc013edab23115
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Router / Console / SimpleRouteStack.php
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
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
8 */
9
10 namespace Zend\Mvc\Router\Console;
11
12 use Traversable;
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;
18
19 /**
20 * Tree search implementation.
21 */
22 class SimpleRouteStack extends BaseSimpleRouteStack
23 {
24 /**
25 * init(): defined by SimpleRouteStack.
26 *
27 * @see BaseSimpleRouteStack::init()
28 */
29 protected function init()
30 {
31 (new Config([
32 'aliases' => [
33 'catchall' => Catchall::class,
34 'catchAll' => Catchall::class,
35 'Catchall' => Catchall::class,
36 'CatchAll' => Catchall::class,
37 'simple' => Simple::class,
38 'Simple' => Simple::class,
39 ],
40 'factories' => [
41 Catchall::class => RouteInvokableFactory::class,
42 Simple::class => RouteInvokableFactory::class,
43
44 // v2 normalized names
45 'zendmvcrouterconsolecatchall' => RouteInvokableFactory::class,
46 'zendmvcrouterconsolesimple' => RouteInvokableFactory::class,
47 ],
48 ]))->configureServiceManager($this->routePluginManager);
49 }
50
51 /**
52 * addRoute(): defined by RouteStackInterface interface.
53 *
54 * @see RouteStackInterface::addRoute()
55 * @param string $name
56 * @param mixed $route
57 * @param int $priority
58 * @return SimpleRouteStack
59 */
60 public function addRoute($name, $route, $priority = null)
61 {
62 if (!$route instanceof RouteInterface) {
63 $route = $this->routeFromArray($route);
64 }
65
66 return parent::addRoute($name, $route, $priority);
67 }
68
69 /**
70 * routeFromArray(): defined by SimpleRouteStack.
71 *
72 * @see BaseSimpleRouteStack::routeFromArray()
73 * @param array|Traversable $specs
74 * @return RouteInterface
75 * @throws Exception\InvalidArgumentException
76 * @throws Exception\RuntimeException
77 */
78 protected function routeFromArray($specs)
79 {
80 if ($specs instanceof Traversable) {
81 $specs = ArrayUtils::iteratorToArray($specs);
82 }
83
84 if (! is_array($specs)) {
85 throw new Exception\InvalidArgumentException('Route definition must be an array or Traversable object');
86 }
87
88 // default to 'simple' console route
89 if (! isset($specs['type'])) {
90 $specs['type'] = Simple::class;
91 }
92
93 // build route object
94 $route = parent::routeFromArray($specs);
95
96 if (! $route instanceof RouteInterface) {
97 throw new Exception\RuntimeException('Given route does not implement Console route interface');
98 }
99
100 return $route;
101 }
102 }