These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * KumbiaPHP web & app Framework |
||
4 | * |
||
5 | * LICENSE |
||
6 | * |
||
7 | * This source file is subject to the new BSD license that is bundled |
||
8 | * with this package in the file LICENSE.txt. |
||
9 | * It is also available through the world-wide-web at this URL: |
||
10 | * http://wiki.kumbiaphp.com/Licencia |
||
11 | * If you did not receive a copy of the license and are unable to |
||
12 | * obtain it through the world-wide-web, please send an email |
||
13 | * to [email protected] so we can send you a copy immediately. |
||
14 | * |
||
15 | * @category Kumbia |
||
16 | * @package Core |
||
17 | * @copyright Copyright (c) 2005 - 2017 Kumbia Team (http://www.kumbiaphp.com) |
||
18 | * @license http://wiki.kumbiaphp.com/Licencia New BSD License |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * Clase principal para el manejo de excepciones |
||
23 | * |
||
24 | * @category Kumbia |
||
25 | * @package Core |
||
26 | */ |
||
27 | class KumbiaException extends Exception |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * View de error de la Excepción |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $view; |
||
36 | |||
37 | /** |
||
38 | * Error 404 para los siguientes views |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected static $view404 = array('no_controller', 'no_action', 'num_params', 'no_view'); |
||
43 | |||
44 | /** |
||
45 | * Path del template de exception |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $template = 'views/templates/exception.phtml'; |
||
50 | |||
51 | /** |
||
52 | * Constructor de la clase; |
||
53 | * |
||
54 | * @param string $message mensaje |
||
55 | * @param string $view vista que se mostrara |
||
56 | */ |
||
57 | public function __construct($message, $view = 'exception') |
||
58 | { |
||
59 | $this->view = $view; |
||
60 | parent::__construct($message); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Maneja las excepciones no capturadas |
||
65 | * |
||
66 | * @param Exception $e |
||
67 | * */ |
||
68 | public static function handleException($e) |
||
69 | { |
||
70 | self::setHeader($e); |
||
71 | //TODO quitar el extract, que el view pida los que necesite |
||
72 | extract(Router::get(), EXTR_OVERWRITE); |
||
73 | // Registra la autocarga de helpers |
||
74 | spl_autoload_register('kumbia_autoload_helper', true, true); |
||
75 | |||
76 | $Controller = Util::camelcase($controller); |
||
77 | ob_start(); |
||
78 | if (PRODUCTION) { //TODO: añadir error 500.phtml |
||
79 | include APP_PATH . 'views/_shared/errors/404.phtml'; |
||
80 | return; |
||
81 | } |
||
82 | if ($e instanceof KumbiaException) { |
||
83 | $view = $e->view; |
||
84 | $tpl = $e->template; |
||
85 | } else { |
||
86 | $view = 'exception'; |
||
87 | $tpl = 'views/templates/exception.phtml'; |
||
88 | } |
||
89 | //Fix problem with action name in REST |
||
90 | $action = $e->getMessage() ?: $action; |
||
91 | |||
92 | include CORE_PATH . "views/errors/{$view}.phtml"; |
||
93 | |||
94 | $content = ob_get_clean(); |
||
95 | |||
96 | // termina los buffers abiertos |
||
97 | while (ob_get_level ()) { |
||
98 | ob_end_clean(); |
||
99 | } |
||
100 | include CORE_PATH . $tpl; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Añade la cabezera de error http |
||
105 | * |
||
106 | * @param Exception $e |
||
107 | * */ |
||
108 | private static function setHeader($e) |
||
109 | { |
||
110 | if (isset($e->view) && in_array($e->view, self::$view404)){ |
||
0 ignored issues
–
show
|
|||
111 | header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); |
||
112 | return; |
||
113 | } |
||
114 | header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error'); |
||
115 | //TODO: mover a los views |
||
116 | } |
||
117 | } |
||
118 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.