ApplicationWithExceptionsInMiddleware.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.6.2
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace TestApp;
  17. use Cake\Error\Middleware\ErrorHandlerMiddleware;
  18. use Cake\Http\BaseApplication;
  19. use Cake\Http\MiddlewareQueue;
  20. use Cake\Routing\Middleware\RoutingMiddleware;
  21. use TestApp\Middleware\ThrowsExceptionMiddleware;
  22. /**
  23. * Simple Application class doing nothing that:
  24. */
  25. class ApplicationWithExceptionsInMiddleware extends BaseApplication
  26. {
  27. /**
  28. * Bootstrap hook.
  29. *
  30. * Nerfed as this is for IntegrationTestCase testing.
  31. */
  32. public function bootstrap(): void
  33. {
  34. // Do nothing.
  35. }
  36. public function middleware(MiddlewareQueue $middlewareQueueQueue): MiddlewareQueue
  37. {
  38. $middlewareQueueQueue
  39. // Catch any exceptions in the lower layers,
  40. // and make an error page/response
  41. ->add(ErrorHandlerMiddleware::class)
  42. // Throw an error
  43. ->add(ThrowsExceptionMiddleware::class)
  44. // Add routing middleware.
  45. ->add(new RoutingMiddleware($this));
  46. return $middlewareQueueQueue;
  47. }
  48. }