Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

Application::middleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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