截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Http.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace think\swoole;
  3. use think\Middleware;
  4. use think\Route;
  5. use think\swoole\concerns\ModifyProperty;
  6. /**
  7. * Class Http
  8. * @package think\swoole
  9. * @property $request
  10. */
  11. class Http extends \think\Http
  12. {
  13. use ModifyProperty;
  14. /** @var Middleware */
  15. protected static $middleware;
  16. /** @var Route */
  17. protected static $route;
  18. protected function loadMiddleware(): void
  19. {
  20. if (!isset(self::$middleware)) {
  21. parent::loadMiddleware();
  22. self::$middleware = clone $this->app->middleware;
  23. $this->modifyProperty(self::$middleware, null);
  24. }
  25. $middleware = clone self::$middleware;
  26. $this->modifyProperty($middleware, $this->app);
  27. $this->app->instance("middleware", $middleware);
  28. }
  29. protected function loadRoutes(): void
  30. {
  31. if (!isset(self::$route)) {
  32. parent::loadRoutes();
  33. self::$route = clone $this->app->route;
  34. $this->modifyProperty(self::$route, null);
  35. $this->modifyProperty(self::$route, null, 'request');
  36. }
  37. }
  38. protected function dispatchToRoute($request)
  39. {
  40. if (isset(self::$route)) {
  41. $newRoute = clone self::$route;
  42. $this->modifyProperty($newRoute, $this->app);
  43. $this->app->instance("route", $newRoute);
  44. }
  45. return parent::dispatchToRoute($request);
  46. }
  47. }