|
| 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 App; |
| 16 | + |
| 17 | +use Cake\Core\Configure; |
| 18 | +use Cake\Core\Exception\MissingPluginException; |
| 19 | +use Cake\Error\Middleware\ErrorHandlerMiddleware; |
| 20 | +use Cake\Http\BaseApplication; |
| 21 | +use Cake\Http\Middleware\CsrfProtectionMiddleware; |
| 22 | +use Cake\Routing\Middleware\AssetMiddleware; |
| 23 | +use Cake\Routing\Middleware\RoutingMiddleware; |
| 24 | + |
| 25 | +/** |
| 26 | + * Application setup class. |
| 27 | + * |
| 28 | + * This defines the bootstrapping logic and middleware layers you |
| 29 | + * want to use in your application. |
| 30 | + */ |
| 31 | +class Application extends BaseApplication |
| 32 | +{ |
| 33 | + /** |
| 34 | + * {@inheritDoc} |
| 35 | + */ |
| 36 | + public function bootstrap() |
| 37 | + { |
| 38 | + // Call parent to load bootstrap from files. |
| 39 | + parent::bootstrap(); |
| 40 | + |
| 41 | + if (PHP_SAPI === 'cli') { |
| 42 | + try { |
| 43 | + $this->addPlugin('Bake'); |
| 44 | + } catch (MissingPluginException $e) { |
| 45 | + // Do not halt if the plugin is missing |
| 46 | + } |
| 47 | + |
| 48 | + $this->addPlugin('Migrations'); |
| 49 | + } |
| 50 | + |
| 51 | + /* |
| 52 | + * Only try to load DebugKit in development mode |
| 53 | + * Debug Kit should not be installed on a production system |
| 54 | + */ |
| 55 | + if (Configure::read('debug')) { |
| 56 | + $this->addPlugin(\DebugKit\Plugin::class); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Define the routes for an application. |
| 62 | + * |
| 63 | + * Use the provided RouteBuilder to define an application's routing, register scoped middleware. |
| 64 | + * |
| 65 | + * @param \Cake\Routing\RouteBuilder $routes A route builder to add routes into. |
| 66 | + * @return void |
| 67 | + */ |
| 68 | + public function routes($routes) |
| 69 | + { |
| 70 | + // Register scoped middleware for use in routes.php |
| 71 | + $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([ |
| 72 | + 'httpOnly' => true |
| 73 | + ])); |
| 74 | + |
| 75 | + parent::routes($routes); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Setup the middleware queue your application will use. |
| 80 | + * |
| 81 | + * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup. |
| 82 | + * @return \Cake\Http\MiddlewareQueue The updated middleware queue. |
| 83 | + */ |
| 84 | + public function middleware($middlewareQueue) |
| 85 | + { |
| 86 | + $middlewareQueue |
| 87 | + // Catch any exceptions in the lower layers, |
| 88 | + // and make an error page/response |
| 89 | + ->add(new ErrorHandlerMiddleware(null, Configure::read('Error'))) |
| 90 | + |
| 91 | + // Handle plugin/theme assets like CakePHP normally does. |
| 92 | + ->add(new AssetMiddleware([ |
| 93 | + 'cacheTime' => Configure::read('Asset.cacheTime') |
| 94 | + ])) |
| 95 | + |
| 96 | + // Add routing middleware. |
| 97 | + // Routes collection cache enabled by default, to disable route caching |
| 98 | + // pass null as cacheConfig, example: `new RoutingMiddleware($this)` |
| 99 | + // you might want to disable this cache in case your routing is extremely simple |
| 100 | + ->add(new RoutingMiddleware($this, '_cake_routes_')); |
| 101 | + |
| 102 | + return $middlewareQueue; |
| 103 | + } |
| 104 | +} |
0 commit comments