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 Method
implements RouteInterface
37 * Create a new method route.
40 * @param array $defaults
42 public function __construct($verb, array $defaults = [])
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['verb'])) {
65 throw new Exception\
InvalidArgumentException('Missing "verb" in options array');
68 if (!isset($options['defaults'])) {
69 $options['defaults'] = [];
72 return new static($options['verb'], $options['defaults']);
76 * match(): defined by RouteInterface interface.
78 * @see \Zend\Mvc\Router\RouteInterface::match()
79 * @param Request $request
80 * @return RouteMatch|null
82 public function match(Request
$request)
84 if (!method_exists($request, 'getMethod')) {
88 $requestVerb = strtoupper($request->getMethod());
89 $matchVerbs = explode(',', strtoupper($this->verb
));
90 $matchVerbs = array_map('trim', $matchVerbs);
92 if (in_array($requestVerb, $matchVerbs)) {
93 return new RouteMatch($this->defaults
);
100 * assemble(): Defined by RouteInterface interface.
102 * @see \Zend\Mvc\Router\RouteInterface::assemble()
103 * @param array $params
104 * @param array $options
107 public function assemble(array $params = [], array $options = [])
109 // The request method does not contribute to the path, thus nothing is returned.
114 * getAssembledParams(): defined by RouteInterface interface.
116 * @see RouteInterface::getAssembledParams
119 public function getAssembledParams()