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;
}
}
}
}