Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ErrorController | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| initialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| viewClasses | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| beforeFilter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| beforeRender | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| afterFilter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | /** |
| 5 | * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
| 6 | * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 7 | * |
| 8 | * Licensed under The MIT License |
| 9 | * For full copyright and license information, please see the LICENSE.txt |
| 10 | * Redistributions of files must retain the above copyright notice. |
| 11 | * |
| 12 | * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 13 | * @link https://cakephp.org CakePHP(tm) Project |
| 14 | * @since 3.3.4 |
| 15 | * @license https://opensource.org/licenses/mit-license.php MIT License |
| 16 | */ |
| 17 | namespace App\Controller; |
| 18 | |
| 19 | use Cake\Event\EventInterface; |
| 20 | use Cake\View\JsonView; |
| 21 | |
| 22 | /** |
| 23 | * Error Handling Controller |
| 24 | * |
| 25 | * Controller used by ExceptionRenderer to render error responses. |
| 26 | */ |
| 27 | class ErrorController extends AppController |
| 28 | { |
| 29 | /** |
| 30 | * Initialization hook method. |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function initialize(): void |
| 35 | { |
| 36 | // Only add parent::initialize() if you are confident your appcontroller is safe. |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get alternate view classes that can be used in |
| 41 | * content-type negotiation. |
| 42 | * |
| 43 | * @return array<string> |
| 44 | */ |
| 45 | public function viewClasses(): array |
| 46 | { |
| 47 | return [JsonView::class]; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * beforeFilter callback. |
| 52 | * |
| 53 | * @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event. |
| 54 | * @return \Cake\Http\Response|null|void |
| 55 | */ |
| 56 | public function beforeFilter(EventInterface $event): void |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * beforeRender callback. |
| 62 | * |
| 63 | * @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event. |
| 64 | * @return \Cake\Http\Response|null|void |
| 65 | */ |
| 66 | public function beforeRender(EventInterface $event): void |
| 67 | { |
| 68 | parent::beforeRender($event); |
| 69 | |
| 70 | $builder = $this->viewBuilder(); |
| 71 | $templatePath = 'Error'; |
| 72 | |
| 73 | if ( |
| 74 | $this->request->getParam('prefix') && |
| 75 | in_array($builder->getTemplate(), ['error400', 'error500'], true) |
| 76 | ) { |
| 77 | $parts = explode(DIRECTORY_SEPARATOR, (string)$builder->getTemplatePath(), -1); |
| 78 | $templatePath = implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR . 'Error'; |
| 79 | } |
| 80 | |
| 81 | $this->viewBuilder()->setTemplatePath($templatePath); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * afterFilter callback. |
| 86 | * |
| 87 | * @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event. |
| 88 | * @return void |
| 89 | */ |
| 90 | public function afterFilter(EventInterface $event): void |
| 91 | { |
| 92 | } |
| 93 | } |