Router::parse PHP Method

parse() public static method

Parses given URL string. Returns 'routing' parameters for that URL.
public static parse ( string $url ) : array
$url string URL to be parsed
return array Parsed elements from URL
    public static function parse($url)
    {
        if (!static::$initialized) {
            static::_loadRoutes();
        }
        $ext = null;
        $out = array();
        if (strlen($url) && strpos($url, '/') !== 0) {
            $url = '/' . $url;
        }
        if (strpos($url, '?') !== false) {
            list($url, $queryParameters) = explode('?', $url, 2);
            parse_str($queryParameters, $queryParameters);
        }
        extract(static::_parseExtension($url));
        foreach (static::$routes as $route) {
            if (($r = $route->parse($url)) !== false) {
                static::$_currentRoute[] = $route;
                $out = $r;
                break;
            }
        }
        if (isset($out['prefix'])) {
            $out['action'] = $out['prefix'] . '_' . $out['action'];
        }
        if (!empty($ext) && !isset($out['ext'])) {
            $out['ext'] = $ext;
        }
        if (!empty($queryParameters) && !isset($out['?'])) {
            $out['?'] = $queryParameters;
        }
        return $out;
    }

Usage Example

Example #1
0
 public static function run()
 {
     session_start();
     $router = new Router();
     list($controller, $action, $mergedParams) = $router->parse();
     return $router->dispatch($controller, $action, $mergedParams);
 }
All Usage Examples Of Router::parse