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\Http
;
13 use Zend\Mvc\Router\Exception
;
14 use Zend\Stdlib\ArrayUtils
;
15 use Zend\Stdlib\RequestInterface
as Request
;
20 class Literal
implements RouteInterface
23 * RouteInterface to match.
37 * Create a new literal route.
39 * @param string $route
40 * @param array $defaults
42 public function __construct($route, array $defaults = [])
44 $this->route
= $route;
45 $this->defaults
= $defaults;
49 * factory(): defined by RouteInterface interface.
51 * @see \Zend\Mvc\Router\RouteInterface::factory()
52 * @param array|Traversable $options
54 * @throws Exception\InvalidArgumentException
56 public static function factory($options = [])
58 if ($options instanceof Traversable
) {
59 $options = ArrayUtils
::iteratorToArray($options);
60 } elseif (!is_array($options)) {
61 throw new Exception\
InvalidArgumentException(__METHOD__
. ' expects an array or Traversable set of options');
64 if (!isset($options['route'])) {
65 throw new Exception\
InvalidArgumentException('Missing "route" in options array');
68 if (!isset($options['defaults'])) {
69 $options['defaults'] = [];
72 return new static($options['route'], $options['defaults']);
76 * match(): defined by RouteInterface interface.
78 * @see \Zend\Mvc\Router\RouteInterface::match()
79 * @param Request $request
80 * @param integer|null $pathOffset
81 * @return RouteMatch|null
83 public function match(Request
$request, $pathOffset = null)
85 if (!method_exists($request, 'getUri')) {
89 $uri = $request->getUri();
90 $path = $uri->getPath();
92 if ($pathOffset !== null) {
93 if ($pathOffset >= 0 && strlen($path) >= $pathOffset && !empty($this->route
)) {
94 if (strpos($path, $this->route
, $pathOffset) === $pathOffset) {
95 return new RouteMatch($this->defaults
, strlen($this->route
));
102 if ($path === $this->route
) {
103 return new RouteMatch($this->defaults
, strlen($this->route
));
110 * assemble(): Defined by RouteInterface interface.
112 * @see \Zend\Mvc\Router\RouteInterface::assemble()
113 * @param array $params
114 * @param array $options
117 public function assemble(array $params = [], array $options = [])
123 * getAssembledParams(): defined by RouteInterface interface.
125 * @see RouteInterface::getAssembledParams
128 public function getAssembledParams()