3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
13 namespace Zend\Mvc\Router\Console
;
16 use Zend\Console\RouteMatcher\DefaultRouteMatcher
;
17 use Zend\Console\Request
as ConsoleRequest
;
18 use Zend\Console\RouteMatcher\RouteMatcherInterface
;
19 use Zend\Filter\FilterChain
;
20 use Zend\Mvc\Router\Exception
;
21 use Zend\Stdlib\ArrayUtils
;
22 use Zend\Stdlib\RequestInterface
as Request
;
23 use Zend\Validator\ValidatorChain
;
28 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
29 * @license http://framework.zend.com/license/new-bsd New BSD License
30 * @see http://guides.rubyonrails.org/routing.html
32 class Simple
implements RouteInterface
35 * List of assembled parameters.
39 protected $assembledParams = [];
42 * @var RouteMatcherInterface
47 * Create a new simple console route.
49 * @param string|RouteMatcherInterface $routeOrRouteMatcher
50 * @param array $constraints
51 * @param array $defaults
52 * @param array $aliases
53 * @param null|array|Traversable|FilterChain $filters
54 * @param null|array|Traversable|ValidatorChain $validators
55 * @throws Exception\InvalidArgumentException
57 public function __construct(
59 array $constraints = [],
65 if (is_string($routeOrRouteMatcher)) {
66 $this->matcher
= new DefaultRouteMatcher($routeOrRouteMatcher, $constraints, $defaults, $aliases);
67 } elseif ($routeOrRouteMatcher instanceof RouteMatcherInterface
) {
68 $this->matcher
= $routeOrRouteMatcher;
70 throw new Exception\
InvalidArgumentException(
71 "routeOrRouteMatcher should either be string, or class implementing RouteMatcherInterface. "
72 . gettype($routeOrRouteMatcher) . " was given."
78 * factory(): defined by Route interface.
80 * @see \Zend\Mvc\Router\RouteInterface::factory()
81 * @param array|Traversable $options
82 * @throws Exception\InvalidArgumentException
85 public static function factory($options = [])
87 if ($options instanceof Traversable
) {
88 $options = ArrayUtils
::iteratorToArray($options);
89 } elseif (!is_array($options)) {
90 throw new Exception\
InvalidArgumentException(__METHOD__
. ' expects an array or Traversable set of options');
93 if (!isset($options['route'])) {
94 throw new Exception\
InvalidArgumentException('Missing "route" in options array');
102 if (!isset($options[$opt])) {
107 if (!isset($options['validators'])) {
108 $options['validators'] = null;
111 if (!isset($options['filters'])) {
112 $options['filters'] = null;
117 $options['constraints'],
118 $options['defaults'],
121 $options['validators']
126 * match(): defined by Route interface.
128 * @see Route::match()
129 * @param Request $request
130 * @param null|int $pathOffset
133 public function match(Request
$request, $pathOffset = null)
135 if (!$request instanceof ConsoleRequest
) {
139 $params = $request->getParams()->toArray();
140 $matches = $this->matcher
->match($params);
142 if (null !== $matches) {
143 return new RouteMatch($matches);
149 * assemble(): Defined by Route interface.
151 * @see \Zend\Mvc\Router\RouteInterface::assemble()
152 * @param array $params
153 * @param array $options
156 public function assemble(array $params = [], array $options = [])
158 $this->assembledParams
= [];
162 * getAssembledParams(): defined by Route interface.
164 * @see RouteInterface::getAssembledParams
167 public function getAssembledParams()
169 return $this->assembledParams
;