use zend router
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Router / Http / Method.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 * Method route.
19 */
20 class Method implements RouteInterface
21 {
22 /**
23 * Verb to match.
24 *
25 * @var string
26 */
27 protected $verb;
28
29 /**
30 * Default values.
31 *
32 * @var array
33 */
34 protected $defaults;
35
36 /**
37 * Create a new method route.
38 *
39 * @param string $verb
40 * @param array $defaults
41 */
42 public function __construct($verb, array $defaults = [])
43 {
44 $this->verb = $verb;
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 Method
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['verb'])) {
65 throw new Exception\InvalidArgumentException('Missing "verb" in options array');
66 }
67
68 if (!isset($options['defaults'])) {
69 $options['defaults'] = [];
70 }
71
72 return new static($options['verb'], $options['defaults']);
73 }
74
75 /**
76 * match(): defined by RouteInterface interface.
77 *
78 * @see \Zend\Mvc\Router\RouteInterface::match()
79 * @param Request $request
80 * @return RouteMatch|null
81 */
82 public function match(Request $request)
83 {
84 if (!method_exists($request, 'getMethod')) {
85 return;
86 }
87
88 $requestVerb = strtoupper($request->getMethod());
89 $matchVerbs = explode(',', strtoupper($this->verb));
90 $matchVerbs = array_map('trim', $matchVerbs);
91
92 if (in_array($requestVerb, $matchVerbs)) {
93 return new RouteMatch($this->defaults);
94 }
95
96 return;
97 }
98
99 /**
100 * assemble(): Defined by RouteInterface interface.
101 *
102 * @see \Zend\Mvc\Router\RouteInterface::assemble()
103 * @param array $params
104 * @param array $options
105 * @return mixed
106 */
107 public function assemble(array $params = [], array $options = [])
108 {
109 // The request method does not contribute to the path, thus nothing is returned.
110 return '';
111 }
112
113 /**
114 * getAssembledParams(): defined by RouteInterface interface.
115 *
116 * @see RouteInterface::getAssembledParams
117 * @return array
118 */
119 public function getAssembledParams()
120 {
121 return [];
122 }
123 }