Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PagesController | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 1 |
| display | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
72 | |||
| 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 0.2.9 |
| 15 | * @license https://opensource.org/licenses/mit-license.php MIT License |
| 16 | */ |
| 17 | namespace App\Controller; |
| 18 | |
| 19 | use Cake\Core\Configure; |
| 20 | use Cake\Http\Exception\ForbiddenException; |
| 21 | use Cake\Http\Exception\NotFoundException; |
| 22 | use Cake\Http\Response; |
| 23 | use Cake\View\Exception\MissingTemplateException; |
| 24 | |
| 25 | /** |
| 26 | * Static content controller |
| 27 | * |
| 28 | * This controller will render views from templates/Pages/ |
| 29 | * |
| 30 | * @link https://book.cakephp.org/4/en/controllers/pages-controller.html |
| 31 | */ |
| 32 | class PagesController extends AppController |
| 33 | { |
| 34 | /** |
| 35 | * Displays a view |
| 36 | * |
| 37 | * @param string ...$path Path segments. |
| 38 | * @return \Cake\Http\Response|null |
| 39 | * @throws \Cake\Http\Exception\ForbiddenException When a directory traversal attempt. |
| 40 | * @throws \Cake\View\Exception\MissingTemplateException When the view file could not |
| 41 | * be found and in debug mode. |
| 42 | * @throws \Cake\Http\Exception\NotFoundException When the view file could not |
| 43 | * be found and not in debug mode. |
| 44 | * @throws \Cake\View\Exception\MissingTemplateException In debug mode. |
| 45 | */ |
| 46 | public function display(string ...$path): ?Response |
| 47 | { |
| 48 | if (!$path) { |
| 49 | return $this->redirect('/'); |
| 50 | } |
| 51 | if (in_array('..', $path, true) || in_array('.', $path, true)) { |
| 52 | throw new ForbiddenException(); |
| 53 | } |
| 54 | $page = $subpage = null; |
| 55 | |
| 56 | if (!empty($path[0])) { |
| 57 | $page = $path[0]; |
| 58 | } |
| 59 | if (!empty($path[1])) { |
| 60 | $subpage = $path[1]; |
| 61 | } |
| 62 | $this->set(compact('page', 'subpage')); |
| 63 | |
| 64 | try { |
| 65 | return $this->render(implode('/', $path)); |
| 66 | } catch (MissingTemplateException $exception) { |
| 67 | if (Configure::read('debug')) { |
| 68 | throw $exception; |
| 69 | } |
| 70 | throw new NotFoundException(); |
| 71 | } |
| 72 | } |
| 73 | } |