lithium\net\http\Router::attached()
Returns an attached mount point configuration.
Router::attach('app', [
'absolute' => true,
'host' => '{:subdomain:[a-z]+}.{:hostname}.{:tld}',
'scheme' => '{:scheme:https://}',
'prefix' => ''
]);
$result = Router::attached('app', [
'subdomain' => 'app',
'hostname' => 'blog',
'tld' => 'co.uk'
]);
// $result is:
// [
// 'absolute' => true,
// 'host' => 'blog.mysite.co.uk',
// 'scheme' => 'http://',
// 'prefix' => ''
// ];
Parameters
-
string
Name
of the scope.
-
array
Optionnal
variables which override the default setted variables with
lithium\net\http\Router::attach()
for population step.
Returns
mixedThe settings array of the scope or an array of settings array
if $name === null
.
Source
public static function attached($name = null, array $vars = []) {
if ($name === false) {
return null;
}
if (!isset(static::$_scopes)) {
static::_initScopes();
}
if ($name === null) {
return static::$_scopes->get();
} elseif (!$config = static::$_scopes->get($name)) {
static::$_scopes->set($name, []);
$config = static::$_scopes->get($name);
}
$vars += $config['values'];
$match = '@\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
$fields = ['scheme', 'host'];
foreach ($fields as $field) {
if (preg_match_all($match, $config[$field], $m)) {
$tokens = $m[0];
$names = $m[1];
$regexs = $m[2];
foreach ($names as $i => $name) {
if (isset($vars[$name])) {
if (($regex = $regexs[$i]) && !preg_match("@^{$regex}\$@", $vars[$name])) {
continue;
}
$config[$field] = str_replace($tokens[$i], $vars[$name], $config[$field]);
}
}
}
}
return $config;
}