lithium\net\http\Route::parse()
Attempts to parse a request object and determine its execution details.
Parameters
-
\lithium\net\http\Request
$request
A request object containing the details of the request to be routed.
-
array
$options
Used to determine the operation of the method, and override certain values in the
Request
object:'url'
string: If present, will be used to match in place of the$url
property of$request
.
Returns
object|booleanIf this route matches $request
, returns the request with
execution details attached to it (inside Request::$params
). Alternatively when
a route handler function was used, returns the result of its invocation. Returns
false
if the route never matched.
Source
public function parse($request, array $options = []) {
$defaults = ['url' => $request->url];
$options += $defaults;
$url = '/' . trim($options['url'], '/');
$pattern = $this->_pattern;
if (!preg_match($pattern, $url, $match)) {
return false;
}
foreach ($this->_meta as $key => $compare) {
$value = $request->get($key);
if (!($compare == $value || (is_array($compare) && in_array($value, $compare)))) {
return false;
}
}
foreach ($this->_config['modifiers'] as $key => $modifier) {
if (isset($match[$key])) {
$match[$key] = $modifier($match[$key]);
}
}
$result = array_intersect_key($match + ['args' => []], $this->_keys);
foreach ($result as $key => $value) {
if ($value === '') {
unset($result[$key]);
}
}
$result += $this->_params + $this->_defaults;
$request->params = $result + (array) $request->params;
$request->persist = array_unique(array_merge($request->persist, $this->_persist));
if ($this->_handler) {
$handler = $this->_handler;
return $handler($request);
}
return $request;
}