lithium\net\http\Router::attached()

public static method

Returns an attached mount point configuration.

Example:

Router::attach('app', array(
    'absolute' => true,
    'host' => '{:subdomain:[a-z]+}.{:hostname}.{:tld}',
    'scheme' => '{:scheme:https://}',
    'prefix' => ''
));
$result = Router::attached('app', array(
    'subdomain' => 'app',
    'hostname' => 'blog',
    'tld' => 'co.uk'
));

Will give the following array in $result:

array( '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

mixed

The settings array of the scope or an array of settings array if $name === null.

Source

	public static function attached($name = null, array $vars = array()) {
		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, array());
			$config = static::$_scopes->get($name);
		}
		$vars += $config['values'];
		$match = '@\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
		$fields = array('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;
	}