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. |
||
9 | * |
||
10 | * @category Kumbia |
||
11 | * @package Controller |
||
12 | * |
||
13 | * @copyright Copyright (c) 2005 - 2023 KumbiaPHP Team (http://www.kumbiaphp.com) |
||
14 | * @license https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE New BSD License |
||
15 | */ |
||
16 | |||
17 | /** |
||
18 | * Clase principal para los controladores de Kumbia |
||
19 | * |
||
20 | * @category Kumbia |
||
21 | * @package Controller |
||
22 | */ |
||
23 | #[\AllowDynamicProperties] |
||
24 | abstract class Controller |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Nombre del modulo actual |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | public string $module_name; |
||
33 | /** |
||
34 | * Nombre del controlador actual |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public string $controller_name; |
||
39 | /** |
||
40 | * Nombre de la acción actual |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | public string $action_name; |
||
45 | /** |
||
46 | * Parámetros de la acción |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | public array $parameters; |
||
51 | /** |
||
52 | * Limita la cantidad correcta de |
||
53 | * parametros de una action |
||
54 | * |
||
55 | * @var bool |
||
56 | */ |
||
57 | public $limit_params = true; |
||
58 | |||
59 | /** |
||
60 | * Data disponble para mostrar |
||
61 | * |
||
62 | * @var mixed |
||
63 | */ |
||
64 | public $data; |
||
65 | |||
66 | public function __construct(array $args) |
||
67 | { |
||
68 | $this->module_name = $args['module']; |
||
69 | $this->controller_name = $args['controller']; |
||
70 | $this->parameters = $args['parameters']; |
||
71 | $this->action_name = $args['action']; |
||
72 | View::init($args['action'], $args['controller_path']); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * BeforeFilter |
||
77 | * |
||
78 | * @return false|null |
||
79 | */ |
||
80 | protected function before_filter() |
||
81 | { |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * AfterFilter |
||
86 | * |
||
87 | * @return false|void |
||
88 | */ |
||
89 | protected function after_filter() |
||
90 | { |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Initialize |
||
95 | * |
||
96 | * @return false|void |
||
97 | */ |
||
98 | protected function initialize() |
||
99 | { |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Finalize |
||
104 | * |
||
105 | * @return false|void |
||
106 | */ |
||
107 | protected function finalize() |
||
108 | { |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Ejecuta los callback filter |
||
113 | * |
||
114 | * @param boolean $init filtros de inicio |
||
115 | * @return false|void |
||
116 | */ |
||
117 | final public function k_callback($init = false) |
||
118 | { |
||
119 | if ($init) { |
||
120 | if ($this->initialize() !== false) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
121 | return $this->before_filter(); |
||
122 | } |
||
123 | return false; |
||
124 | } |
||
125 | |||
126 | $this->after_filter(); |
||
127 | $this->finalize(); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Se llama cuando no existe un método |
||
132 | * |
||
133 | * @param string $name |
||
134 | * @param array $arguments |
||
135 | * @throws KumbiaException |
||
136 | * |
||
137 | * @return void |
||
138 | */ |
||
139 | public function __call($name, $arguments) |
||
140 | { |
||
141 | throw new KumbiaException($name, 'no_action'); |
||
142 | } |
||
143 | } |
||
144 |