Navigation.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. ApplicationSettings::RegisterDefaultSetting("navigation", "mode", "exclude");
  3. ApplicationSettings::RegisterDefaultSetting("navigation", "pages", "");
  4. require_once 'Controller/Navigation/base/INavigationController.php';
  5. Navigation::Load();
  6. class Navigation {
  7. private static $_controllers=array();
  8. public static function LoadNavigationController($name){
  9. include_once "Controller/Navigation/$name.php";
  10. $controller=new $name;
  11. self::RegisterPage($name,$controller);
  12. }
  13. public static function Load(){
  14. $mode=ApplicationSettings::GetSetting("navigation", "mode");
  15. $pages=ApplicationSettings::GetSetting("navigation", "pages");
  16. $pageList=explode(",", $pages);
  17. switch (strtolower($mode)){
  18. case "include":
  19. foreach ($pageList as $page)
  20. self::LoadNavigationController($page);
  21. break;
  22. case "exclude":
  23. $files=glob("Controller/Navigation/*.php");
  24. foreach ($files as $file){
  25. $page=basename($file,".php");
  26. if (!in_array($page, $pageList))
  27. self::LoadNavigationController($page);
  28. }
  29. break;
  30. default:
  31. throw new Exception("Invalid navigiation mode: $mode. Please set to include or exclude.");
  32. }
  33. }
  34. public static function RegisterPage($name, INavigationController $contoller){
  35. self::$_controllers[$name]=$contoller;
  36. }
  37. public static function Get(){
  38. return self::$_controllers;
  39. }
  40. }