9c91fbc915c1fe39c24f19f903becd3053fc2e30.svn-base 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php namespace Maze\Routing;
  2. use Maze\Template\View;
  3. use Maze\Http\Output;
  4. use Maze\Security\Api;
  5. use Maze\Debug\Process as Debug;
  6. use Maze\Config\Load as Config;
  7. class Route
  8. {
  9. /**
  10. * Run the route service
  11. *
  12. * @return mixed
  13. */
  14. public function runing()
  15. {
  16. $uri = Uri::get();
  17. # 直接读取数据库或者类
  18. //if(strpos($uri, '-') !== false || strpos($uri, '.') !== false)
  19. # 更新只允许数据库中的带有*前缀的方法接口访问
  20. if(strpos($uri, '.') !== false || strpos($uri, '-*') !== false)
  21. {
  22. # 不允许带有_的直接浏览器访问
  23. if(strpos($uri, '._') !== false)
  24. {
  25. Output::abert('error_page');
  26. }
  27. Api::check($uri);
  28. $this->content = Load::get($uri, array());
  29. Api::out($this->content);
  30. }
  31. # 直接读取模板
  32. else
  33. {
  34. $this->content = View::getInstance(Uri::file())->runing();
  35. }
  36. return $this;
  37. }
  38. /**
  39. * out
  40. *
  41. * @return mixed
  42. */
  43. public function output()
  44. {
  45. if(!$this->content)
  46. {
  47. Output::abert('error_page');
  48. }
  49. $this->debug();
  50. Output::result($this->content, true, false);
  51. }
  52. /**
  53. * debug
  54. *
  55. * @return mixed
  56. */
  57. private function debug()
  58. {
  59. if(Debug::init() && is_string($this->content))
  60. {
  61. if(strpos($this->content, '</body>') >= 0)
  62. {
  63. $this->content = str_replace('</body>', Debug::html() . '</body>', $this->content);
  64. }
  65. else
  66. {
  67. $this->content = $this->content . Debug::html('');
  68. }
  69. }
  70. }
  71. }