3 namespace Services\Routing
;
5 use Services\Routing\IRoute
;
7 class Route
implements IRoute
9 private $_controllerName;
14 public function __construct($pattern, array $methods, $controllerName, $actionName = null
)
16 $this->_controllerName
= $controllerName;
17 $this->_actionName
= $actionName;
18 $this->_pattern
= $pattern;
19 $this->_methods
= $methods;
22 public function matches($path) {
26 * Set up a callback for preg_replace_callback. What this does is
27 * replace the :argName style arguments with named groups to match
28 * against the resource URI. So for example:
34 * my/(?P<pattern>[^/]+
36 * Then we can feed the new regex and the URI in to preg_match to
37 * extract the variables.
39 $callback = function($m) use ($argNames) {
41 * We save away the names of the arguments in a variable so we can
42 * loop through later and put them in $this->arguments.
45 return '(?P<' . $m[1] . '>[^/]+)';
48 $patternAsRegex = preg_replace_callback('#:([\w]+)\+?#', $callback, $this->_pattern
);
50 if (!preg_match('#^' . $patternAsRegex . '$#', $path, $argValues))
56 public function supports($method)
58 return in_array($method, $this->_methods
);
61 public function getControllerName()
63 return $this->_controllerName
;
66 public function getActionName()
68 return $this->_actionName
;