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
|
|
|
|
16
|
|
|
namespace App; |
17
|
|
|
|
18
|
|
|
use Cake\Core\Configure; |
19
|
|
|
use Cake\Core\Exception\MissingPluginException; |
20
|
|
|
use Cake\Error\Middleware\ErrorHandlerMiddleware; |
21
|
|
|
use Cake\Http\BaseApplication; |
22
|
|
|
use Cake\Http\MiddlewareQueue; |
23
|
|
|
use Cake\Routing\Middleware\AssetMiddleware; |
24
|
|
|
use Cake\Routing\Middleware\RoutingMiddleware; |
25
|
|
|
use DebugKit\Plugin; |
26
|
|
|
use const PHP_SAPI; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Application setup class. |
30
|
|
|
* |
31
|
|
|
* This defines the bootstrapping logic and middleware layers you |
32
|
|
|
* want to use in your application. |
33
|
|
|
*/ |
34
|
|
|
class Application extends BaseApplication |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
168 |
|
public function bootstrap(): void |
42
|
|
|
{ |
43
|
|
|
// Call parent to load bootstrap from files. |
44
|
168 |
|
parent::bootstrap(); |
45
|
|
|
|
46
|
168 |
|
if (PHP_SAPI === 'cli') { |
47
|
168 |
|
$this->bootstrapCli(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/* |
51
|
|
|
* Only try to load DebugKit in development mode |
52
|
|
|
* Debug Kit should not be installed on a production system |
53
|
|
|
*/ |
54
|
168 |
|
if (Configure::read('debug')) { |
55
|
|
|
$this->addPlugin(Plugin::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Load more plugins here |
59
|
168 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Setup the middleware queue your application will use. |
63
|
|
|
* |
64
|
|
|
* @param MiddlewareQueue $middlewareQueue The middleware queue to setup. |
65
|
|
|
* @return MiddlewareQueue The updated middleware queue. |
66
|
|
|
*/ |
67
|
147 |
|
public function middleware($middlewareQueue): MiddlewareQueue |
68
|
|
|
{ |
69
|
|
|
$middlewareQueue |
70
|
|
|
// Catch any exceptions in the lower layers, |
71
|
|
|
// and make an error page/response |
72
|
147 |
|
->add(new ErrorHandlerMiddleware(Configure::read('Error'))) |
73
|
|
|
|
74
|
|
|
// Handle plugin/theme assets like CakePHP normally does. |
75
|
147 |
|
->add(new AssetMiddleware([ |
76
|
147 |
|
'cacheTime' => Configure::read('Asset.cacheTime'), |
77
|
|
|
])) |
78
|
|
|
|
79
|
|
|
// Add routing middleware. |
80
|
|
|
// If you have a large number of routes connected, turning on routes |
81
|
|
|
// caching in production could improve performance. For that when |
82
|
|
|
// creating the middleware instance specify the cache config name by |
83
|
|
|
// using it's second constructor argument: |
84
|
|
|
// `new RoutingMiddleware($this, '_cake_routes_')` |
85
|
147 |
|
->add(new RoutingMiddleware($this)); |
86
|
|
|
|
87
|
147 |
|
return $middlewareQueue; |
88
|
|
|
} |
89
|
|
|
|
90
|
168 |
|
protected function bootstrapCli(): void |
91
|
|
|
{ |
92
|
|
|
try { |
93
|
168 |
|
$this->addPlugin('Bake'); |
94
|
|
|
} catch (MissingPluginException $e) {// phpcs:ignore |
95
|
|
|
// Do not halt if the plugin is missing |
96
|
|
|
} |
97
|
|
|
|
98
|
168 |
|
$this->addPlugin('Migrations'); |
99
|
|
|
|
100
|
|
|
// Load more plugins here |
101
|
168 |
|
} |
102
|
|
|
} |
103
|
|
|
|