Application.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.3.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp;
  16. use Cake\Http\BaseApplication;
  17. use Cake\Routing\Middleware\RoutingMiddleware;
  18. use Cake\Routing\RouteBuilder;
  19. use TestApp\Command\AbortCommand;
  20. class Application extends BaseApplication
  21. {
  22. /**
  23. * @return void
  24. */
  25. public function bootstrap()
  26. {
  27. parent::bootstrap();
  28. }
  29. /**
  30. * @param \Cake\Console\CommandCollection $commands
  31. * @return \Cake\Console\CommandCollection
  32. */
  33. public function console($commands)
  34. {
  35. return $commands
  36. ->add('abort_command', new AbortCommand())
  37. ->addMany($commands->autoDiscover());
  38. }
  39. /**
  40. * @param \Cake\Http\MiddlewareQueue $middleware
  41. * @return \Cake\Http\MiddlewareQueue
  42. */
  43. public function middleware($middleware)
  44. {
  45. $middleware->add(new RoutingMiddleware($this));
  46. $middleware->add(function ($req, $res, $next) {
  47. /** @var \Cake\Http\ServerRequest $res */
  48. $res = $next($req, $res);
  49. return $res->withHeader('X-Middleware', 'true');
  50. });
  51. return $middleware;
  52. }
  53. /**
  54. * Routes hook, used for testing with RoutingMiddleware.
  55. *
  56. * @param \Cake\Routing\RouteBuilder $routes
  57. * @return void
  58. */
  59. public function routes($routes)
  60. {
  61. $routes->scope('/app', function (RouteBuilder $routes) {
  62. $routes->connect('/articles', ['controller' => 'Articles']);
  63. $routes->fallbacks();
  64. });
  65. }
  66. }