Completed
Pull Request — master (#10)
by Stefano
04:08
created

BaseApplication::bootstrap()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 19
rs 10
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2018 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace BEdita\WebTools;
14
15
use BEdita\WebTools\Shell\CacheShell;
16
use Cake\Core\Configure;
17
use Cake\Error\Middleware\ErrorHandlerMiddleware;
18
use Cake\Http\BaseApplication as CakeBaseApplication;
19
use Cake\Http\MiddlewareQueue;
20
use Cake\Routing\Middleware\AssetMiddleware;
21
use Cake\Routing\Middleware\RoutingMiddleware;
22
23
/**
24
 * Application setup base class.
25
 *
26
 * This defines the bootstrapping logic and middleware layers you
27
 * want to use in your application.
28
 */
29
class BaseApplication extends CakeBaseApplication
30
{
31
    /**
32
     * {@inheritDoc}
33
     *
34
     * Replace CakePHP `cache` command with \BEdita\WebTools\Shell\CacheShell
35
     */
36
    public function console($commands)
37
    {
38
        return $commands->addMany($commands->autoDiscover())
39
            ->add('cache', CacheShell::class);
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45
    public function bootstrap()
46
    {
47
        // Call parent to load bootstrap from files.
48
        parent::bootstrap();
49
        
50
        if (PHP_SAPI === 'cli') {
51
            $this->bootstrapCli();
52
        }
53
54
        /*
55
         * Only try to load DebugKit in development mode
56
         * Debug Kit should not be installed on a production system
57
         */
58
        if (Configure::read('debug')) {
59
            $this->addPlugin(\DebugKit\Plugin::class);
0 ignored issues
show
Bug introduced by
The type DebugKit\Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
        }
61
62
        // Load more plugins here
63
        $this->addPlugin('WyriHaximus/TwigView', ['bootstrap' => true]);
64
    }
65
66
    /**
67
     * Setup the middleware queue your application will use.
68
     *
69
     * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
70
     * @return \Cake\Http\MiddlewareQueue The updated middleware queue.
71
     */
72
    public function middleware($middlewareQueue) : MiddlewareQueue
73
    {
74
        $middlewareQueue
75
            // Catch any exceptions in the lower layers,
76
            // and make an error page/response
77
            ->add(new ErrorHandlerMiddleware(null, Configure::read('Error')))
78
79
            // Handle plugin/theme assets like CakePHP normally does.
80
            ->add(new AssetMiddleware([
81
                'cacheTime' => Configure::read('Asset.cacheTime')
82
            ]))
83
84
            // Add routing middleware.
85
            // If you have a large number of routes connected, turning on routes
86
            // caching in production could improve performance. For that when
87
            // creating the middleware instance specify the cache config name by
88
            // using it's second constructor argument:
89
            // `new RoutingMiddleware($this, '_cake_routes_')`
90
            ->add(new RoutingMiddleware($this));
91
92
        return $middlewareQueue;
93
    }
94
95
    /**
96
     * @return void
97
     */
98
    protected function bootstrapCli()
99
    {
100
        try {
101
            $this->addPlugin('Bake');
102
        } catch (MissingPluginException $e) {
0 ignored issues
show
Bug introduced by
The type BEdita\WebTools\MissingPluginException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
103
            // Do not halt if the plugin is missing
104
        }
105
106
        $this->addPlugin('Migrations');
107
108
        // Load more plugins here
109
    }
110
}
111