diff --git a/src/bootstrap.php b/src/bootstrap.php index e957fd5..b82276d 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -24,7 +24,7 @@ $file = ''; switch ($className) { case 'PanaceaControllerFactory': - case 'PanaceaPageController': + case 'PanaceaDefaultController': case 'PanaceaViewFactory': $file = "$path/lib/$className.php"; break; diff --git a/src/lib/PanaceaControllerFactory.php b/src/lib/PanaceaControllerFactory.php index 0b31175..e539c46 100644 --- a/src/lib/PanaceaControllerFactory.php +++ b/src/lib/PanaceaControllerFactory.php @@ -58,19 +58,27 @@ * @return PanaceaPageController */ public function getController(array $uriFragments) { - if (count($uriFragments) < 2) { - throw new InvalidTypeException(1, 'array with at least two elements', $uriFragments); + if (empty($uriFragments)) { + throw new InvalidTypeException(1, 'non-empty array', $uriFragments); } $section = ''; $page = $uriFragments[0]; if (isset($uriFragments[1])) { - $section = $uriFragments[0]; + $section = ucfirst($uriFragments[0]); $page = $uriFragments[1]; } + if (empty($section)) { + $section = 'Default'; + } + if (empty($page)) { + $page = 'home'; + } - return new PanaceaPageController($uriFragments[0]); + $controllerName = 'Panacea' . $section . 'Controller'; + + return new $controllerName($page); } } diff --git a/src/lib/PanaceaPageController.php b/src/lib/PanaceaPageController.php index b3309bc..a730002 100644 --- a/src/lib/PanaceaPageController.php +++ b/src/lib/PanaceaPageController.php @@ -1,7 +1,7 @@