title: Whoops meta:

  • name: description content: Easyswoole provides the Whoops driver for the development phase, friendly troubleshooting of HTTP business errors and exceptions.
  • name: keywords content: swoole|swoole extension|swoole framework|easyswoole|Whoops

Whoops

Easyswoole provides the Whoops driver for the development phase, friendly troubleshooting of HTTP business errors and exceptions.

Whoops - 图1

::: warning Do not use it in the production phase, otherwise the code leaks EasySwoole is not responsible for it! ! ! :::

Installation

  1. composer require easyswoole/easy-whoops=3.x

Use

Register directly in the event of EasySwoole global

  1. use EasySwoole\EasySwoole\Swoole\EventRegister;
  2. use EasySwoole\EasySwoole\AbstractInterface\Event;
  3. use EasySwoole\Http\Request;
  4. use EasySwoole\Http\Response;
  5. use EasySwoole\Whoops\Handler\CallbackHandler;
  6. use EasySwoole\Whoops\Handler\PrettyPageHandler;
  7. use EasySwoole\Whoops\Run;
  8. class EasySwooleEvent implements Event
  9. {
  10. public static function initialize()
  11. {
  12. // TODO: Implement initialize() method.
  13. date_default_timezone_set('Asia/Shanghai');
  14. $whoops = new Run();
  15. $whoops->pushHandler(new PrettyPageHandler); // Output a nice page
  16. $whoops->pushHandler(new CallbackHandler(function ($exception, $inspector, $run, $handle) {
  17. // Can push multiple Handle support callbacks for more follow-up
  18. }));
  19. $whoops->register();
  20. }
  21. public static function mainServerCreate(EventRegister $register)
  22. {
  23. Run::attachTemplateRender(ServerManager::getInstance()->getSwooleServer());
  24. }
  25. public static function onRequest(Request $request, Response $response): bool
  26. {
  27. //Intercept request
  28. Run::attachRequest($request, $response);
  29. return true;
  30. }
  31. public static function afterRequest(Request $request, Response $response): void
  32. {
  33. // TODO: Implement afterAction() method.
  34. }
  35. }