public function parse($url, $method = '')
{
if (empty($this->_compiledRoute)) {
$this->compile();
}
list($url, $ext) = $this->_parseExtension($url);
if (!preg_match($this->_compiledRoute, urldecode($url), $route)) {
return false;
}
if (isset($this->defaults['_method'])) {
if (empty($method)) {
// Deprecated reading the global state is deprecated and will be removed in 4.x
$request = Router::getRequest(true) ?: Request::createFromGlobals();
$method = $request->env('REQUEST_METHOD');
}
if (!in_array($method, (array) $this->defaults['_method'], true)) {
return false;
}
}
array_shift($route);
$count = count($this->keys);
for ($i = 0; $i <= $count; $i++) {
unset($route[$i]);
}
$route['pass'] = [];
// Assign defaults, set passed args to pass
foreach ($this->defaults as $key => $value) {
if (isset($route[$key])) {
continue;
}
if (is_int($key)) {
$route['pass'][] = $value;
continue;
}
$route[$key] = $value;
}
if (isset($route['_args_'])) {
$pass = $this->_parseArgs($route['_args_'], $route);
$route['pass'] = array_merge($route['pass'], $pass);
unset($route['_args_']);
}
if (isset($route['_trailing_'])) {
$route['pass'][] = $route['_trailing_'];
unset($route['_trailing_']);
}
if (!empty($ext)) {
$route['_ext'] = $ext;
}
// restructure 'pass' key route params
if (isset($this->options['pass'])) {
$j = count($this->options['pass']);
while ($j--) {
if (isset($route[$this->options['pass'][$j]])) {
array_unshift($route['pass'], $route[$this->options['pass'][$j]]);
}
}
}
$route['_matchedRoute'] = $this->template;
return $route;
}