Application.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. *
  32. * @return \Cake\Console\CommandCollection
  33. */
  34. public function console($commands)
  35. {
  36. return $commands
  37. ->add('abort_command', new AbortCommand())
  38. ->addMany($commands->autoDiscover());
  39. }
  40. /**
  41. * @param \Cake\Http\MiddlewareQueue $middleware
  42. *
  43. * @return \Cake\Http\MiddlewareQueue
  44. */
  45. public function middleware($middleware)
  46. {
  47. $middleware->add(new RoutingMiddleware());
  48. $middleware->add(function ($req, $res, $next) {
  49. /** @var \Cake\Http\ServerRequest $res */
  50. $res = $next($req, $res);
  51. return $res->withHeader('X-Middleware', 'true');
  52. });
  53. return $middleware;
  54. }
  55. /**
  56. * Routes hook, used for testing with RoutingMiddleware.
  57. *
  58. * @param \Cake\Routing\RouteBuilder $routes
  59. * @return void
  60. */
  61. public function routes($routes)
  62. {
  63. $routes->scope('/app', function (RouteBuilder $routes) {
  64. $routes->connect('/articles', ['controller' => 'Articles']);
  65. });
  66. }
  67. }