Index.php 830 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace EasySwoole\Http\Tests\Controller;
  3. use EasySwoole\Http\AbstractInterface\Controller;
  4. class Index extends Controller
  5. {
  6. protected $handler = false;
  7. public function index()
  8. {
  9. $this->response()->write('index');
  10. }
  11. public function exception()
  12. {
  13. throw new \Exception('the error');
  14. }
  15. public function httpExceptionHandler(){
  16. $this->handler = true;
  17. throw new \Exception('the handler');
  18. }
  19. public function actionNotFound(?string $action)
  20. {
  21. return $this->response()->withStatus(404)->write("{$action}-404");
  22. }
  23. protected function onException(\Throwable $throwable): void
  24. {
  25. if ($this->handler === true) throw $throwable;
  26. $this->response()->withStatus(500)->write("error-{$throwable->getMessage()}");
  27. }
  28. }