Application::middleware()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
11
 * @link      http://cakephp.org CakePHP(tm) Project
12
 * @since     3.3.0
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
namespace CakeDC\Api\Test\App;
17
18
use Authentication\AuthenticationService;
19
use Authentication\Middleware\AuthenticationMiddleware;
20
use CakeDC\Api\Middleware\ApiMiddleware;
21
use Cake\Core\Configure;
22
use Cake\Error\Middleware\ErrorHandlerMiddleware;
23
use Cake\Http\BaseApplication;
24
use Cake\Routing\Middleware\AssetMiddleware;
25
use Cake\Routing\Middleware\RoutingMiddleware;
26
use CakeDC\Api\Service\ServiceRegistry;
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
    public function bootstrap()
37
    {
38
        parent::bootstrap();
39
        ServiceRegistry::getServiceLocator()->clear();
40
41
        $this->addPlugin('CakeDC/Users', [
42
            'path' => ROOT . DS . 'vendor' . DS . 'cakedc' . DS . 'users' . DS
43
        ]);
44
        $this->addPlugin('CakeDC/Api', [
45
            'path' => ROOT . DS
46
        ]);
47
    }
48
49
    public function pluginBootstrap()
50
    {
51
        parent::pluginBootstrap();
52
53
        Configure::load('api');
54
        Configure::write('Users.config', ['users']);
55
    }
56
57
    /**
58
     * Setup the middleware your application will use.
59
     *
60
     * @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to setup.
61
     * @return \Cake\Http\MiddlewareQueue The updated middleware.
62
     */
63
    public function middleware($middleware)
64
    {
65
        $middleware
66
            // Catch any exceptions in the lower layers,
67
            // and make an error page/response
68
            ->add(new ErrorHandlerMiddleware(Configure::read('Error.exceptionRenderer')))
69
            // ->add($authentication)
70
            // Apply Api
71
            ->add(new ApiMiddleware())
72
            // Handle plugin/theme assets like CakePHP normally does.
73
            ->add(new AssetMiddleware())// Apply routing
74
            ->add(new RoutingMiddleware($this));
75
76
        return $middleware;
77
    }
78
}
79