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
|
|
|
namespace CakeDC\Api\Test\App; |
16
|
|
|
|
17
|
|
|
use Authentication\AuthenticationService; |
18
|
|
|
use Authentication\Middleware\AuthenticationMiddleware; |
19
|
|
|
use CakeDC\Api\Middleware\ApiMiddleware; |
20
|
|
|
use Cake\Core\Configure; |
21
|
|
|
use Cake\Error\Middleware\ErrorHandlerMiddleware; |
22
|
|
|
use Cake\Http\BaseApplication; |
23
|
|
|
use Cake\Routing\Middleware\AssetMiddleware; |
24
|
|
|
use Cake\Routing\Middleware\RoutingMiddleware; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Application setup class. |
28
|
|
|
* |
29
|
|
|
* This defines the bootstrapping logic and middleware layers you |
30
|
|
|
* want to use in your application. |
31
|
|
|
*/ |
32
|
|
|
class Application extends BaseApplication |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Setup the middleware your application will use. |
36
|
|
|
* |
37
|
|
|
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to setup. |
38
|
|
|
* @return \Cake\Http\MiddlewareQueue The updated middleware. |
39
|
|
|
*/ |
40
|
|
|
public function middleware($middleware) |
41
|
|
|
{ |
42
|
|
|
// $service = new AuthenticationService(); |
|
|
|
|
43
|
|
|
|
44
|
|
|
// $service->loadIdentifier('Authentication.Token', [ |
|
|
|
|
45
|
|
|
// 'dataField' => 'token', |
|
|
|
|
46
|
|
|
// 'tokenField' => 'api_token', |
|
|
|
|
47
|
|
|
// ]); |
48
|
|
|
// $service->loadAuthenticator('Authentication.Token', [ |
|
|
|
|
49
|
|
|
// 'queryParam' => 'token', |
|
|
|
|
50
|
|
|
// ]); |
51
|
|
|
|
52
|
|
|
// Add it to the authentication middleware |
53
|
|
|
// $authentication = new AuthenticationMiddleware($service); |
|
|
|
|
54
|
|
|
|
55
|
|
|
// Add the middleware to the middleware queue |
56
|
|
|
|
57
|
|
|
$middleware// Catch any exceptions in the lower layers, |
58
|
|
|
// and make an error page/response |
59
|
|
|
->add(new ErrorHandlerMiddleware(Configure::read('Error.exceptionRenderer'))) |
60
|
|
|
|
61
|
|
|
// ->add($authentication) |
|
|
|
|
62
|
|
|
// Apply Api |
63
|
|
|
->add(new ApiMiddleware()) |
64
|
|
|
|
65
|
|
|
// Handle plugin/theme assets like CakePHP normally does. |
66
|
|
|
->add(new AssetMiddleware())// Apply routing |
67
|
|
|
->add(new RoutingMiddleware()); |
68
|
|
|
|
69
|
|
|
return $middleware; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.