Extends
lithium\core\Object
Attempts to parse a request object and determine its execution details.
Parameters
- object $request A request object, usually an instance of `lithium\net\http\Request`, 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
mixed If this route matches `$request`, returns an array of the execution details contained in the route, otherwise returns false.Source
public function parse($request, array $options = array()) {
$defaults = array('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;
}
}
if (isset($match['args'])) {
$match['args'] = explode('/', $match['args']);
}
if (isset($this->_keys['args'])) {
$match += array('args' => array());
}
$result = array_intersect_key($match, $this->_keys) + $this->_params + $this->_defaults;
if (isset($result['action']) && !$result['action']) {
$result['action'] = 'index';
}
$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;
}