Application.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. spl_autoload_register(function($class){
  3. if (file_exists("Interfaces/$class.php")){
  4. include("Interfaces/$class.php");
  5. return;
  6. }
  7. if (file_exists("Model/$class.php"))
  8. include("Model/$class.php");
  9. });
  10. /*include_once 'ApplicationSettings.php';
  11. include_once 'View.php';
  12. include_once 'Helper.php';
  13. include_once 'IConvertible.php';*/
  14. $files=glob("base/*.php");
  15. foreach ($files as $file)
  16. require_once $file;
  17. class Application{
  18. private $_view, $_controller;
  19. function __construct($url) {
  20. // session_start();
  21. $page=ApplicationSettings::GetSetting("general", "default_page");
  22. $action="Index";
  23. $params=array();
  24. $parts=explode("/", $url, 3);
  25. switch (count($parts)){
  26. case 3:
  27. if ($parts[2]!='')
  28. $params=explode("/",$parts[2]);
  29. case 2:
  30. //$action=ucfirst($parts[1]);
  31. $action=$parts[1];
  32. case 1:
  33. if ($parts[0]!="")
  34. $page=$parts[0];
  35. $controller=self::FindControllerPath($page);
  36. if ($controller===false){
  37. $controller="Controller/E404.php";
  38. $params=array($url);
  39. }
  40. break;
  41. }
  42. foreach ($_GET as $key=>$_)
  43. $params[$key]=filter_input(INPUT_GET, $key);
  44. foreach ($_POST as $key=>$_)
  45. $params[$key]=filter_input(INPUT_POST, $key);
  46. //$params['cookies']=array();;
  47. //foreach ($_COOKIE as $key=>$_)
  48. // $params['cookies'][$key]=filter_input(INPUT_COOKIE, $key);
  49. include_once $controller;
  50. $this->_controller=new $page();
  51. if (!method_exists($this->_controller, $action))
  52. $action="Index";
  53. $this->_view=$this->_controller->$action($params);
  54. }
  55. public function GetOutput(){
  56. if (gettype($this->_view)=="object")
  57. return $this->_view->GetHTMLFromTemplate(ApplicationSettings::GetSetting("general", "template"));
  58. switch (gettype($this->_view)){
  59. case "string":
  60. case "integer":
  61. return $this->_view;
  62. }
  63. return "";
  64. }
  65. public static function FindControllerPath($controller){
  66. $controllerLower=strtolower($controller);
  67. $files=glob("Controller/*.php");
  68. foreach ($files as $file)
  69. if (strtolower(basename($file,".php"))==$controllerLower)
  70. return $file;
  71. return false;
  72. }
  73. }