WorkerManAdmin.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. require_once WORKERMAN_ROOT_DIR . 'man/Core/SocketWorker.php';
  3. require_once WORKERMAN_ROOT_DIR . 'applications/Common/Protocols/Http.php';
  4. /**
  5. *
  6. * WorkerMan 管理后台
  7. * HTTP协议
  8. *
  9. * @author walkor <worker-man@qq.com>
  10. */
  11. class WorkerManAdmin extends Man\Core\SocketWorker
  12. {
  13. protected static $typeMap = array(
  14. 'js' => 'text/javascript',
  15. 'png' => 'image/png',
  16. 'jpg' => 'image/jpeg',
  17. 'gif' => 'image/gif',
  18. 'png' => 'image/png',
  19. 'css' => 'text/css',
  20. );
  21. public function onStart()
  22. {
  23. App\Common\Protocols\HttpCache::init();
  24. }
  25. /**
  26. * 确定数据是否接收完整
  27. * @see Man\Core.SocketWorker::dealInput()
  28. */
  29. public function dealInput($recv_str)
  30. {
  31. return App\Common\Protocols\http_input($recv_str);
  32. }
  33. /**
  34. * 数据接收完整后处理业务逻辑
  35. * @see Man\Core.SocketWorker::dealProcess()
  36. */
  37. public function dealProcess($recv_str)
  38. {
  39. /**
  40. * 解析http协议,生成$_POST $_GET $_COOKIE
  41. */
  42. App\Common\Protocols\http_start($recv_str);
  43. //App\Common\Protocols\session_start();
  44. ob_start();
  45. $pos = strpos($_SERVER['REQUEST_URI'], '?');
  46. $file = $_SERVER['REQUEST_URI'];
  47. if($pos !== false)
  48. {
  49. $file = substr($_SERVER['REQUEST_URI'], 0, $pos);
  50. }
  51. $file = WORKERMAN_ROOT_DIR . 'applications/Wordpress/'.$file;
  52. if(!is_file($file))
  53. {
  54. $file = WORKERMAN_ROOT_DIR . 'applications/Wordpress/index.php';
  55. }
  56. if(is_file($file))
  57. {
  58. $extension = pathinfo($file, PATHINFO_EXTENSION);
  59. if($extension == 'php')
  60. {
  61. include $file;
  62. }
  63. else
  64. {
  65. if(isset(self::$typeMap[$extension]))
  66. {
  67. App\Common\Protocols\header('Content-Type: '. self::$typeMap[$extension]);
  68. }
  69. echo file_get_contents($file);
  70. }
  71. }
  72. else
  73. {
  74. echo 'index.php missed';
  75. }
  76. $content = ob_get_clean();
  77. $buffer = App\Common\Protocols\http_end($content);
  78. $this->sendToClient($buffer);
  79. }
  80. }