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

_compileScope() protected static method

Compiles the scope into regular expression patterns for matching against request URLs
protected static _compileScope ( array $config ) : array
$config array Array of settings.
return array Returns the complied settings.
    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;
    }