public function determineSelectedRoute()
    {
        if (empty($this->routes))
        {
            $this->getRoutingTable();
        }

        if (empty($this->segments)) {
            $this->segments = array('/');
        }

        $currentLevel = &$this->routes;
        //$parentSegment = '/';
        $index = 0;
        $isRoot = true;

        foreach ($this->segments as $segment) {
            $segmentIsInteger = is_numeric($segment);

            //Static route test, numeric segments are not allowed to be traversed
            if (!$segmentIsInteger && !empty($currentLevel[$segment])) {
                $this->addDebugMessage("Traversing " . $segment);

                $currentLevel = &$currentLevel[$segment];
                $index = 0;
                $isRoot = false;
                continue;
            }

            if ($isRoot && !empty($this->routes['/'])) {
                $currentLevel = &$this->routes['/'];
            }

            //We've hit a dead end here. The current tree branch does not have a static segment to match $segment
            if (!empty($currentLevel))
            {
                foreach ($currentLevel as $route) {
                    if ($route instanceof \Slab\Router\Route) {
                        $this->addDebugMessage("Checking route " . $route->getName());

                        $validationDebug = [];
                        if ($route->validateDynamicPattern($this->currentRequest, $validationDebug)) {
                            $this->addDebugMessage("Dynamic pattern match for route " . $route->getName());

                            $this->selectedRoute = &$route;
                            return true;
                        }
                    }

                    ++$index;
                }
            }

            $this->addDebugMessage("All hope is lost!");

            return false;
        }

        if (!empty($currentLevel))
        {
            foreach ($currentLevel as &$route)
            {
                if (!($route instanceof \Slab\Router\Route)) continue;

                /**
                 * @var \Slab\Router\Route $route
                 */
                if (!$route->isDynamic())
                {
                    $this->selectedRoute = &$route;
                    $this->addDebugMessage("Found matching static route: " . $this->selectedRoute->getName());

                    return true;
                }
                else
                {
                    $validationDebug = [];
                    if ($route->validateDynamicPattern($this->currentRequest, $validationDebug))
                    {
                        $this->selectedRoute = &$route;
                        $this->addDebugMessage("Found matching dynamic route: " . $this->selectedRoute->getName());

                        return true;
                    }
                }
            }

        }

        $this->addDebugMessage("Unable to find a matching route.");

        return false;
    }
public function determineSelectedRoute()
    {
        if (empty($this->routes))
        {
            $this->getRoutingTable();
        }

        if (empty($this->segments)) {
            $this->segments = array('/');
        }

        $currentLevel = &$this->routes;
        //$parentSegment = '/';
        $index = 0;
        $isRoot = true;

        foreach ($this->segments as $segment) {
            $segmentIsInteger = is_numeric($segment);

            //Static route test, numeric segments are not allowed to be traversed
            if (!$segmentIsInteger && !empty($currentLevel[$segment])) {
                $this->addDebugMessage("Traversing " . $segment);

                $currentLevel = &$currentLevel[$segment];
                $index = 0;
                $isRoot = false;
                continue;
            }

            if ($isRoot && !empty($this->routes['/'])) {
                $currentLevel = &$this->routes['/'];
            }

            //We've hit a dead end here. The current tree branch does not have a static segment to match $segment
            if (!empty($currentLevel))
            {
                foreach ($currentLevel as $route) {
                    if ($route instanceof \Slab\Router\Route) {
                        $this->addDebugMessage("Checking route " . $route->getName());

                        $validationDebug = [];
                        if ($route->validateDynamicPattern($this->currentRequest, $validationDebug)) {
                            $this->addDebugMessage("Dynamic pattern match for route " . $route->getName());

                            $this->selectedRoute = &$route;
                            return true;
                        }
                    }

                    ++$index;
                }
            }

            $this->addDebugMessage("All hope is lost!");

            return false;
        }

        if (!empty($currentLevel))
        {
            foreach ($currentLevel as &$route)
            {
                if (!($route instanceof \Slab\Router\Route)) continue;

                /**
                 * @var \Slab\Router\Route $route
                 */
                if (!$route->isDynamic())
                {
                    $this->selectedRoute = &$route;
                    $this->addDebugMessage("Found matching static route: " . $this->selectedRoute->getName());

                    return true;
                }
                else
                {
                    $validationDebug = [];
                    if ($route->validateDynamicPattern($this->currentRequest, $validationDebug))
                    {
                        $this->selectedRoute = &$route;
                        $this->addDebugMessage("Found matching dynamic route: " . $this->selectedRoute->getName());

                        return true;
                    }
                }
            }

        }

        $this->addDebugMessage("Unable to find a matching route.");

        return false;
    }
public function determineSelectedRoute ( ) { if ( empty ( $ this -> routes ) ) { $ this -> getRoutingTable ( ) ; } if ( empty ( $ this -> segments ) ) { $ this -> segments = array ( '/' ) ; } $ currentLevel = & $ this -> routes ; //$parentSegment = '/'; $ index = 0 ; $ isRoot = true ; foreach ( $ this -> segments as $ segment ) { $ segmentIsInteger = is_numeric ( $ segment ) ; //Static route test, numeric segments are not allowed to be traversed if ( ! $ segmentIsInteger && ! empty ( $ currentLevel [ $ segment ] ) ) { $ this -> addDebugMessage ( "Traversing " . $ segment ) ; $ currentLevel = & $ currentLevel [ $ segment ] ; $ index = 0 ; $ isRoot = false ; continue ; } if ( $ isRoot && ! empty ( $ this -> routes [ '/' ] ) ) { $ currentLevel = & $ this -> routes [ '/' ] ; } //We've hit a dead end here. The current tree branch does not have a static segment to match $segment if ( ! empty ( $ currentLevel ) ) { foreach ( $ currentLevel as $ route ) { if ( $ route instanceof \ Slab \ Router \ Route ) { $ this -> addDebugMessage ( "Checking route " . $ route -> getName ( ) ) ; $ validationDebug = [ ] ; if ( $ route -> validateDynamicPattern ( $ this -> currentRequest , $ validationDebug ) ) { $ this -> addDebugMessage ( "Dynamic pattern match for route " . $ route -> getName ( ) ) ; $ this -> selectedRoute = & $ route ; return true ; } } ++ $ index ; } } $ this -> addDebugMessage ( "All hope is lost!" ) ; return false ; } if ( ! empty ( $ currentLevel ) ) { foreach ( $ currentLevel as & $ route ) { if ( ! ( $ route instanceof \ Slab \ Router \ Route ) ) continue ; /**
                 * @var \Slab\Router\Route $route
                 */ if ( ! $ route -> isDynamic ( ) ) { $ this -> selectedRoute = & $ route ; $ this -> addDebugMessage ( "Found matching static route: " . $ this -> selectedRoute -> getName ( ) ) ; return true ; } else { $ validationDebug = [ ] ; if ( $ route -> validateDynamicPattern ( $ this -> currentRequest , $ validationDebug ) ) { $ this -> selectedRoute = & $ route ; $ this -> addDebugMessage ( "Found matching dynamic route: " . $ this -> selectedRoute -> getName ( ) ) ; return true ; } } } } $ this -> addDebugMessage ( "Unable to find a matching route." ) ; return false ; }
Determine the actually selected route from URL params
Determine the actually selected route from URL params