lithium\net\http\Router::_compileScope()
Compiles the scope into regular expression patterns for matching against request URLs
Parameters
-
array
$config
Array of settings.
Returns
arrayReturns the complied settings.
Source
protected static function _compileScope(array $config) {
$defaults = array(
'absolute' => false,
'host' => null,
'scheme' => null,
'base' => null,
'prefix' => '',
'pattern' => '',
'params' => array()
);
$config += $defaults;
$config['prefix'] = trim($config['prefix'], '/');
$prefix = '/' . ($config['prefix'] ? $config['prefix'] . '/' : '');
if (!$config['absolute']) {
$config['pattern'] = "@^{$prefix}@";
} else {
$fields = array('scheme', 'host');
foreach ($fields as $field) {
$dots = '/(?!\{[^\}]*)\.(?![^\{]*\})/';
$pattern[$field] = preg_replace($dots, '\.', $config[$field]);
$match = '@\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
if (preg_match_all($match, $pattern[$field], $m)) {
$tokens = $m[0];
$names = $m[1];
$regexs = $m[2];
foreach ($names as $i => $name) {
$regex = $regexs[$i] ? : '[^/]+?';
$pattern[$field] = str_replace(
$tokens[$i],
"(?P<{$name}>{$regex})",
$pattern[$field]
);
$config['params'][] = $name;
}
}
}
$pattern['host'] = $pattern['host'] ? : 'localhost';
$pattern['scheme'] = $pattern['scheme'] . ($pattern['scheme'] ? '://' : '(.*?)//');
$config['pattern'] = "@^{$pattern['scheme']}{$pattern['host']}{$prefix}@";
}
return $config;
}