Test Setup Failed
Push — upgrade-cakephp4 ( 25b5b0 )
by giu
04:14
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 83
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 32 1
A bootstrapCli() 0 9 2
A bootstrap() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
13
 * @link      https://cakephp.org CakePHP(tm) Project
14
 * @since     3.3.0
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 */
17
namespace App;
18
19
use Cake\Core\Configure;
20
use Cake\Core\Exception\MissingPluginException;
21
use Cake\Error\Middleware\ErrorHandlerMiddleware;
22
use Cake\Http\BaseApplication;
23
use Cake\Http\Middleware\BodyParserMiddleware;
24
use Cake\Http\Middleware\CsrfProtectionMiddleware;
25
use Cake\Http\MiddlewareQueue;
26
use Cake\Routing\Middleware\AssetMiddleware;
27
use Cake\Routing\Middleware\RoutingMiddleware;
28
29
/**
30
 * Application setup class.
31
 *
32
 * This defines the bootstrapping logic and middleware layers you
33
 * want to use in your application.
34
 */
35
class Application extends BaseApplication
36
{
37
    /**
38
     * Load all the application configuration and bootstrap logic.
39
     *
40
     * @return void
41
     */
42
    public function bootstrap(): void
43
    {
44
        // Call parent to load bootstrap from files.
45
        parent::bootstrap();
46
47
        if (PHP_SAPI === 'cli') {
48
            $this->bootstrapCli();
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');
57
        }
58
59
        // Load more plugins here
60
    }
61
62
    /**
63
     * Setup the middleware queue your application will use.
64
     *
65
     * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
66
     * @return \Cake\Http\MiddlewareQueue The updated middleware queue.
67
     */
68
    public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
69
    {
70
        $middlewareQueue
71
            // Catch any exceptions in the lower layers,
72
            // and make an error page/response
73
            ->add(new ErrorHandlerMiddleware(Configure::read('Error')))
74
75
            // Handle plugin/theme assets like CakePHP normally does.
76
            ->add(new AssetMiddleware([
77
                'cacheTime' => Configure::read('Asset.cacheTime'),
78
            ]))
79
80
            // Add routing middleware.
81
            // If you have a large number of routes connected, turning on routes
82
            // caching in production could improve performance. For that when
83
            // creating the middleware instance specify the cache config name by
84
            // using it's second constructor argument:
85
            // `new RoutingMiddleware($this, '_cake_routes_')`
86
            ->add(new RoutingMiddleware($this))
87
88
            // Parse various types of encoded request bodies so that they are
89
            // available as array through $request->getData()
90
            // https://book.cakephp.org/4/en/controllers/middleware.html#body-parser-middleware
91
            ->add(new BodyParserMiddleware())
92
93
            // Cross Site Request Forgery (CSRF) Protection Middleware
94
            // https://book.cakephp.org/4/en/controllers/middleware.html#cross-site-request-forgery-csrf-middleware
95
            ->add(new CsrfProtectionMiddleware([
96
                'httponly' => true,
97
            ]));
98
99
        return $middlewareQueue;
100
    }
101
102
    /**
103
     * Bootrapping for CLI application.
104
     *
105
     * That is when running commands.
106
     *
107
     * @return void
108
     */
109
    protected function bootstrapCli(): void
110
    {
111
        try {
112
            $this->addPlugin('Bake');
113
        } catch (MissingPluginException $e) {
114
            // Do not halt if the plugin is missing
115
        }
116
117
        $this->addPlugin('Migrations');
118
119
        // Load more plugins here
120
    }
121
}
122