use zend router
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Router / Http / Literal.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\Http;
11
12 use Traversable;
13 use Zend\Mvc\Router\Exception;
14 use Zend\Stdlib\ArrayUtils;
15 use Zend\Stdlib\RequestInterface as Request;
16
17 /**
18 * Literal route.
19 */
20 class Literal implements RouteInterface
21 {
22 /**
23 * RouteInterface to match.
24 *
25 * @var string
26 */
27 protected $route;
28
29 /**
30 * Default values.
31 *
32 * @var array
33 */
34 protected $defaults;
35
36 /**
37 * Create a new literal route.
38 *
39 * @param string $route
40 * @param array $defaults
41 */
42 public function __construct($route, array $defaults = [])
43 {
44 $this->route = $route;
45 $this->defaults = $defaults;
46 }
47
48 /**
49 * factory(): defined by RouteInterface interface.
50 *
51 * @see \Zend\Mvc\Router\RouteInterface::factory()
52 * @param array|Traversable $options
53 * @return Literal
54 * @throws Exception\InvalidArgumentException
55 */
56 public static function factory($options = [])
57 {
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');
62 }
63
64 if (!isset($options['route'])) {
65 throw new Exception\InvalidArgumentException('Missing "route" in options array');
66 }
67
68 if (!isset($options['defaults'])) {
69 $options['defaults'] = [];
70 }
71
72 return new static($options['route'], $options['defaults']);
73 }
74
75 /**
76 * match(): defined by RouteInterface interface.
77 *
78 * @see \Zend\Mvc\Router\RouteInterface::match()
79 * @param Request $request
80 * @param integer|null $pathOffset
81 * @return RouteMatch|null
82 */
83 public function match(Request $request, $pathOffset = null)
84 {
85 if (!method_exists($request, 'getUri')) {
86 return;
87 }
88
89 $uri = $request->getUri();
90 $path = $uri->getPath();
91
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));
96 }
97 }
98
99 return;
100 }
101
102 if ($path === $this->route) {
103 return new RouteMatch($this->defaults, strlen($this->route));
104 }
105
106 return;
107 }
108
109 /**
110 * assemble(): Defined by RouteInterface interface.
111 *
112 * @see \Zend\Mvc\Router\RouteInterface::assemble()
113 * @param array $params
114 * @param array $options
115 * @return mixed
116 */
117 public function assemble(array $params = [], array $options = [])
118 {
119 return $this->route;
120 }
121
122 /**
123 * getAssembledParams(): defined by RouteInterface interface.
124 *
125 * @see RouteInterface::getAssembledParams
126 * @return array
127 */
128 public function getAssembledParams()
129 {
130 return [];
131 }
132 }