Blame view

src/Application.php 4.59 KB
66ad693c   Etienne Pallier   Evolution du fram...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

// https://book.cakephp.org/3/en/development/application.html

/**
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link      https://cakephp.org CakePHP(tm) Project
 * @since     3.3.0
 * @license   https://opensource.org/licenses/mit-license.php MIT License
 */
namespace App;

use Cake\Core\Configure;
use Cake\Core\Exception\MissingPluginException;
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\BaseApplication;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;

/**
 * Application setup class.
 *
 * This defines the bootstrapping logic and middleware layers you
 * want to use in your application.
 */
class Application extends BaseApplication
{
    /**
     * {@inheritDoc}
     */
    public function bootstrap()
    {
        // Call parent to load bootstrap from files.
        parent::bootstrap();

        if (PHP_SAPI === 'cli') {
            $this->bootstrapCli();
        }

        /*
         * Only try to load DebugKit in development mode
         * Debug Kit should not be installed on a production system
         */
        // DebugKit (cf https://book.cakephp.org/debugkit/3/fr/index.html)
        if (Configure::read('debug')) {
            $this->addPlugin('DebugKit');
            // Whitelister mes sites locaux :
            Configure::write('DebugKit.safeTld', ['localhost', 'dev', 'invalid', 'test', 'example', 'local', 'devv']);
            /* (EP 20200316 added pour éviter l'erreur suivante retrouvée dans logs/error.log :
             * 2020-03-16 12:20:28 Warning: DebugKit is disabling itself as your host `labinvent.devv` is not in the known safe list of top-level-domains
             * (localhost, invalid, test, example, local). If you would like to force DebugKit on
             * use the `DebugKit.forceEnable` Configure option.
             */
            //Configure::write('DebugKit.forceEnable', true);
            // Autres options dispo :
            //Configure::write('DebugKit.ignoreAuthorization', true);
            //Configure::write('DebugKit.panels', ['DebugKit.Packages' => false]);
            // Maintenant on peut charger DebugKit normalement
            //Plugin::load('DebugKit', ['bootstrap' => true]);
            
            // ORIG
            //Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true]);
        }
        
        // Load more plugins here
        
        /* (EP)
         * Pour générer du pdf (à la place de fpdf qui ne marche pas au CRAL)
         */
        $this->addPlugin('Dompdf');
        
        /*
         * Bootstrap-ui (EP added 28/1/2020)
         * https://github.com/FriendsOfCake/bootstrap-ui/tree/develop
         */
        $this->addPlugin('BootstrapUI');
        
    }

    /**
     * Setup the middleware queue your application will use.
     *
     * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
     * @return \Cake\Http\MiddlewareQueue The updated middleware queue.
     */
    public function middleware($middlewareQueue)
    {
        $middlewareQueue
            // Catch any exceptions in the lower layers,
            // and make an error page/response
            ->add(new ErrorHandlerMiddleware(null, Configure::read('Error')))

            // Handle plugin/theme assets like CakePHP normally does.
            ->add(new AssetMiddleware([
                'cacheTime' => Configure::read('Asset.cacheTime'),
            ]))

            // Add routing middleware.
            // If you have a large number of routes connected, turning on routes
            // caching in production could improve performance. For that when
            // creating the middleware instance specify the cache config name by
            // using it's second constructor argument:
            // `new RoutingMiddleware($this, '_cake_routes_')`
            ->add(new RoutingMiddleware($this));

        return $middlewareQueue;
    }

    /**
     * @return void
     */
    protected function bootstrapCli()
    {
        try {
            $this->addPlugin('Bake');
        } catch (MissingPluginException $e) {
            // Do not halt if the plugin is missing
        }

        // cf https://book.cakephp.org/3.0/en/migrations.html
        $this->addPlugin('Migrations');

        // Load more plugins here
    }
}