public function match(array $options = array())
{
$defaults = array('action' => 'index', 'http:method' => 'GET');
$query = null;
if (!$this->_config['continue']) {
$options += $defaults;
if (isset($options['?'])) {
$query = $options['?'];
$query = '?' . (is_array($query) ? http_build_query($query) : $query);
unset($options['?']);
}
}
if (!($options = $this->_matchMethod($options))) {
return false;
}
if (!($options = $this->_matchKeys($options))) {
return false;
}
foreach ($options as $key => $value) {
if (isset($this->_config['formatters'][$key])) {
$options[$key] = $this->_config['formatters'][$key]($value);
}
}
foreach ($this->_subPatterns as $key => $pattern) {
if (isset($options[$key]) && !preg_match("/^{$pattern}\$/", $options[$key])) {
return false;
}
}
$defaults = $this->_defaults + $defaults;
if ($this->_config['continue']) {
return $this->_write(array('args' => '{:args}') + $options, $this->_defaults);
}
return $this->_write($options, $defaults + array('args' => '')) . $query;
}
/** * Tests that a single route with default values matches its default parameters, as well as * non-default parameters. */ public function testSingleRouteWithDefaultValues() { $defaults = array('controller' => 'Admin', 'action' => 'index'); $route = new Route(compact('defaults') + array('template' => '/{:controller}/{:action}', 'pattern' => '@^(?:/(?P[^\\/]+)?)?(?:/(?P[^\\/]+)?)?$@u', 'params' => array('controller' => 'Admin', 'action' => 'index'), 'keys' => array('controller' => 'controller', 'action' => 'action'), 'match' => array())); $this->assertIdentical('/', $route->match($defaults)); $nonDefault = array('controller' => 'Admin', 'action' => 'view'); $this->assertIdentical('/Admin/view', $route->match($nonDefault)); }