lithium\net\http\Router::attached PHP Method

attached() public static method

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' => '' ));
public static attached ( $name = null, array $vars = [] ) : mixed
$vars array
return mixed The settings array of the scope or an array of settings array if `$name === null`.
    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;
    }

Usage Example

Example #1
0
 protected function _saveCtrlContext()
 {
     $this->_context['scope'] = Router::scope(false);
     $this->_context['routes'] = Router::get();
     $this->_context['scopes'] = Router::attached();
     Router::reset();
 }
All Usage Examples Of lithium\net\http\Router::attached