Pop\Mvc\Router::traverseControllers PHP Méthode

traverseControllers() protected méthode

Traverse the controllers based on the path
protected traverseControllers ( array $controllers, integer $depth ) : string
$controllers array
$depth integer
Résultat string
    protected function traverseControllers($controllers, $depth = 0)
    {
        $next = $depth + 1;
        // If the path stem exists in the controllers, the traverse it
        if ($this->request->getPath($depth) != '' && array_key_exists('/' . $this->request->getPath($depth), $controllers)) {
            $this->basePath .= '/' . $this->request->getPath($depth);
            // If the next level is an array, traverse it
            if (is_array($controllers['/' . $this->request->getPath($depth)])) {
                return $this->traverseControllers($controllers['/' . $this->request->getPath($depth)], $next);
                // Else, return the controller class name
            } else {
                return isset($controllers['/' . $this->request->getPath($depth)]) ? $controllers['/' . $this->request->getPath($depth)] : null;
            }
            // Else check for the root '/' path
        } else {
            if (array_key_exists('/', $controllers)) {
                $this->basePath .= '/';
                // If the next level is an array, traverse it
                if (is_array($controllers['/'])) {
                    return $this->traverseControllers($controllers['/'], $next);
                    // Else, return the controller class name
                } else {
                    return isset($controllers['/']) ? $controllers['/'] : null;
                }
            }
        }
    }