3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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\Http
;
13 use Zend\Mvc\Router\Exception
;
14 use Zend\Mvc\Router\Http\RouteMatch
;
15 use Zend\Stdlib\ArrayUtils
;
16 use Zend\Stdlib\RequestInterface
as Request
;
23 class Query
implements RouteInterface
33 * List of assembled parameters.
37 protected $assembledParams = array();
40 * Create a new wildcard route.
42 * @param array $defaults
44 public function __construct(array $defaults = array())
47 * Legacy purposes only, to prevent code that uses it from breaking.
49 trigger_error('Query route deprecated as of ZF 2.1.4; use the "query" option of the HTTP router\'s assembling method instead', E_USER_DEPRECATED
);
50 $this->defaults
= $defaults;
54 * factory(): defined by RouteInterface interface.
56 * @see \Zend\Mvc\Router\RouteInterface::factory()
57 * @param array|Traversable $options
59 * @throws Exception\InvalidArgumentException
61 public static function factory($options = array())
63 if ($options instanceof Traversable
) {
64 $options = ArrayUtils
::iteratorToArray($options);
65 } elseif (!is_array($options)) {
66 throw new Exception\
InvalidArgumentException(__METHOD__
. ' expects an array or Traversable set of options');
69 if (!isset($options['defaults'])) {
70 $options['defaults'] = array();
73 return new static($options['defaults']);
77 * match(): defined by RouteInterface interface.
79 * @see \Zend\Mvc\Router\RouteInterface::match()
80 * @param Request $request
83 public function match(Request
$request)
85 // We don't merge the query parameters into the rotue match here because
86 // of possible security problems. Use the Query object instead which is
87 // included in the Request object.
88 return new RouteMatch($this->defaults
);
92 * Recursively urldecodes keys and values from an array
97 protected function recursiveUrldecode(array $array)
101 foreach ($array as $key => $value) {
102 if (is_array($value)) {
103 $matches[urldecode($key)] = $this->recursiveUrldecode($value);
105 $matches[urldecode($key)] = urldecode($value);
113 * assemble(): Defined by RouteInterface interface.
115 * @see \Zend\Mvc\Router\RouteInterface::assemble()
116 * @param array $params
117 * @param array $options
120 public function assemble(array $params = array(), array $options = array())
122 $mergedParams = array_merge($this->defaults
, $params);
123 $this->assembledParams
= array();
125 if (isset($options['uri']) && count($mergedParams)) {
126 foreach ($mergedParams as $key => $value) {
127 $this->assembledParams
[] = $key;
130 $options['uri']->setQuery($mergedParams);
133 // A query does not contribute to the path, thus nothing is returned.
138 * getAssembledParams(): defined by RouteInterface interface.
140 * @see RouteInterface::getAssembledParams
143 public function getAssembledParams()
145 return $this->assembledParams
;