src/Maleeby/MRest/Routing.php
private static function _mainDispatcher($uri, $config) {
        $uriInfo = self::analizeUri();
        $uri = $uriInfo['uri'];
        $uriItems = explode('/', $uri);
        $attributes = [];

        foreach ($config['routes'] as $routePattern => $className) {
            if (preg_match('#' . $routePattern . '#', $uri)) {
                $class = $className;
                $itemCount = count(explode('/', str_replace('\\/', '/', $routePattern)));

                for ($i = 0; $i < $itemCount; $i++) {
                    unset($uriItems[$i]);
                }
                $attributes = array_values($uriItems);
                break;
            }
        }

        if (!$class) {
            $class = self::_getController($uri, 'App\\');
            $classUri = self::_getControllerBaseUri($class);
            
            if(strpos($uri, $classUri) === 0 && strlen($uri) > strlen($classUri)) {
                $attributesUri = substr($uri, strlen($classUri)+1);
                $attributes = explode('/', $attributesUri);
            }
        }
        
        return [
            'class' => self::fixNamespace($class ? $class : self::_getController($uri, 'App\\')),
            'method' => strtolower($_SERVER['REQUEST_METHOD']),
            'attributes' => $attributes
        ];
    }
private static function _mainDispatcher($uri, $config) {
        $uriInfo = self::analizeUri();
        $uri = $uriInfo['uri'];
        $uriItems = explode('/', $uri);
        $attributes = [];

        foreach ($config['routes'] as $routePattern => $className) {
            if (preg_match('#' . $routePattern . '#', $uri)) {
                $class = $className;
                $itemCount = count(explode('/', str_replace('\\/', '/', $routePattern)));

                for ($i = 0; $i < $itemCount; $i++) {
                    unset($uriItems[$i]);
                }
                $attributes = array_values($uriItems);
                break;
            }
        }

        if (!$class) {
            $class = self::_getController($uri, 'App\\');
            $classUri = self::_getControllerBaseUri($class);
            
            if(strpos($uri, $classUri) === 0 && strlen($uri) > strlen($classUri)) {
                $attributesUri = substr($uri, strlen($classUri)+1);
                $attributes = explode('/', $attributesUri);
            }
        }
        
        return [
            'class' => self::fixNamespace($class ? $class : self::_getController($uri, 'App\\')),
            'method' => strtolower($_SERVER['REQUEST_METHOD']),
            'attributes' => $attributes
        ];
    }
private static function _mainDispatcher ( $ uri , $ config ) { $ uriInfo = self :: analizeUri ( ) ; $ uri = $ uriInfo [ 'uri' ] ; $ uriItems = explode ( '/' , $ uri ) ; $ attributes = [ ] ; foreach ( $ config [ 'routes' ] as $ routePattern => $ className ) { if ( preg_match ( '#' . $ routePattern . '#' , $ uri ) ) { $ class = $ className ; $ itemCount = count ( explode ( '/' , str_replace ( '\\/' , '/' , $ routePattern ) ) ) ; for ( $ i = 0 ; $ i < $ itemCount ; $ i ++ ) { unset ( $ uriItems [ $ i ] ) ; } $ attributes = array_values ( $ uriItems ) ; break ; } } if ( ! $ class ) { $ class = self :: _getController ( $ uri , 'App\\' ) ; $ classUri = self :: _getControllerBaseUri ( $ class ) ; if ( strpos ( $ uri , $ classUri ) === 0 && strlen ( $ uri ) > strlen ( $ classUri ) ) { $ attributesUri = substr ( $ uri , strlen ( $ classUri ) + 1 ) ; $ attributes = explode ( '/' , $ attributesUri ) ; } } return [ 'class' => self :: fixNamespace ( $ class ? $ class : self :: _getController ( $ uri , 'App\\' ) ) , 'method' => strtolower ( $ _SERVER [ 'REQUEST_METHOD' ] ) , 'attributes' => $ attributes ] ; }
Main dispatcher. Looks for patterns from the config.

@param string $uri Current URI
@param array $config Routing configuration

@return string Controller's callback
Main dispatcher . Looks for patterns from the config .