application.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * application.class.php PHPCMS应用程序创建类
  4. *
  5. * @copyright (C) 2005-2010 PHPCMS
  6. * @license http://www.phpcms.cn/license/
  7. * @lastmodify 2010-6-7
  8. */
  9. class application {
  10. /**
  11. * 构造函数
  12. */
  13. public function __construct() {
  14. $param = pc_base::load_sys_class('param');
  15. define('ROUTE_M', $param->route_m());
  16. define('ROUTE_C', $param->route_c());
  17. define('ROUTE_A', $param->route_a());
  18. $this->init();
  19. }
  20. /**
  21. * 调用件事
  22. */
  23. private function init() {
  24. $controller = $this->load_controller();
  25. if (method_exists($controller, ROUTE_A)) {
  26. if (preg_match('/^[_]/i', ROUTE_A)) {
  27. exit('You are visiting the action is to protect the private action');
  28. } else {
  29. call_user_func(array($controller, ROUTE_A));
  30. }
  31. } else {
  32. exit('Action does not exist.');
  33. }
  34. }
  35. /**
  36. * 加载控制器
  37. * @param string $filename
  38. * @param string $m
  39. * @return obj
  40. */
  41. private function load_controller($filename = '', $m = '') {
  42. if (empty($filename)) $filename = ROUTE_C;
  43. if (empty($m)) $m = ROUTE_M;
  44. $filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php';
  45. if (file_exists($filepath)) {
  46. $classname = $filename;
  47. include $filepath;
  48. if ($mypath = pc_base::my_path($filepath)) {
  49. $classname = 'MY_'.$filename;
  50. include $mypath;
  51. }
  52. if(class_exists($classname)){
  53. return new $classname;
  54. }else{
  55. exit('Controller does not exist.');
  56. }
  57. } else {
  58. exit('Controller does not exist.');
  59. }
  60. }
  61. }