Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PagesController | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
| display | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
90 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Static content controller. |
| 5 | * |
| 6 | * This file will render views from views/pages/ |
| 7 | * |
| 8 | * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
| 9 | * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 10 | * |
| 11 | * Licensed under The MIT License |
| 12 | * For full copyright and license information, please see the LICENSE.txt |
| 13 | * Redistributions of files must retain the above copyright notice. |
| 14 | * |
| 15 | * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 16 | * @link https://cakephp.org CakePHP(tm) Project |
| 17 | * @package app.Controller |
| 18 | * @since CakePHP(tm) v 0.2.9 |
| 19 | * @license https://opensource.org/licenses/mit-license.php MIT License |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Static content controller |
| 24 | * |
| 25 | * Override this controller by placing a copy in controllers directory of an application |
| 26 | * |
| 27 | * @link https://book.cakephp.org/2.0/en/controllers/pages-controller.html |
| 28 | */ |
| 29 | class PagesController extends AppController |
| 30 | { |
| 31 | /** |
| 32 | * This controller does not use a model |
| 33 | * |
| 34 | * @var array<string> |
| 35 | */ |
| 36 | public $uses = []; |
| 37 | |
| 38 | /** |
| 39 | * Displays a view |
| 40 | * |
| 41 | * @param string ...$path |
| 42 | * @throws ForbiddenException When a directory traversal attempt. |
| 43 | * @throws NotFoundException When the view file could not be found |
| 44 | * @throws MissingViewException When the view file could not be found in debug mode. |
| 45 | * @return CakeResponse|null |
| 46 | */ |
| 47 | public function display(string ...$path) |
| 48 | { |
| 49 | $count = count($path); |
| 50 | if (!$count) |
| 51 | return $this->redirect('/'); |
| 52 | if (in_array('..', $path, true) || in_array('.', $path, true)) |
| 53 | throw new ForbiddenException(); |
| 54 | $page = $subpage = $title_for_layout = null; |
| 55 | |
| 56 | if (!empty($path[0])) |
| 57 | $page = $path[0]; |
| 58 | if (!empty($path[1])) |
| 59 | $subpage = $path[1]; |
| 60 | if (!empty($path[$count - 1])) |
| 61 | $title_for_layout = Inflector::humanize($path[$count - 1]); |
| 62 | $this->set(compact('page', 'subpage', 'title_for_layout')); |
| 63 | |
| 64 | try |
| 65 | { |
| 66 | return $this->render(implode('/', $path)); |
| 67 | } |
| 68 | catch (MissingViewException $e) |
| 69 | { |
| 70 | if (Configure::read('debug')) |
| 71 | throw $e; |
| 72 | |
| 73 | throw new NotFoundException(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | } |