|
| 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 | + * Redistributions of files must retain the above copyright notice. |
| 8 | + * |
| 9 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 10 | + * @link http://cakephp.org CakePHP(tm) Project |
| 11 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 12 | + */ |
| 13 | +namespace DebugKit\Controller; |
| 14 | + |
| 15 | +use Cake\Controller\Controller; |
| 16 | +use Cake\Core\Configure; |
| 17 | +use Cake\Event\Event; |
| 18 | +use Cake\Http\Exception\NotFoundException; |
| 19 | +use Cake\Log\Log; |
| 20 | + |
| 21 | +/** |
| 22 | + * DebugKit Controller. |
| 23 | + */ |
| 24 | +class DebugKitController extends Controller |
| 25 | +{ |
| 26 | + /** |
| 27 | + * Before filter handler. |
| 28 | + * |
| 29 | + * @param \Cake\Event\Event $event The event. |
| 30 | + * @return void |
| 31 | + * @throws \Cake\Http\Exception\NotFoundException |
| 32 | + */ |
| 33 | + public function beforeFilter(Event $event) |
| 34 | + { |
| 35 | + if (!Configure::read('debug')) { |
| 36 | + throw new NotFoundException('Not available without debug mode on.'); |
| 37 | + } |
| 38 | + |
| 39 | + // If CakePHP Authorization\Authorization plugin is enabled, |
| 40 | + // ignore it, only if `DebugKit.ignoreAuthorization` is set to true |
| 41 | + $authorizationService = $this->getRequest()->getAttribute('authorization'); |
| 42 | + if ($authorizationService instanceof \Authorization\AuthorizationService) { |
| 43 | + if (Configure::read('DebugKit.ignoreAuthorization')) { |
| 44 | + $authorizationService->skipAuthorization(); |
| 45 | + } else { |
| 46 | + Log::info( |
| 47 | + "Cake Authorization plugin is enabled. If you would like " . |
| 48 | + "to force DebugKit to ignore it, set `DebugKit.ignoreAuthorization` " . |
| 49 | + " Configure option to true." |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments