@@ -27,19 +27,19 @@ discard block |
||
27 | 27 | $custom_template = null; |
28 | 28 | $method = $this->router()->target_method(); |
29 | 29 | |
30 | - foreach(['prepare', "before_$method", $method, "after_$method"] as $step => $chainling) |
|
30 | + foreach (['prepare', "before_$method", $method, "after_$method"] as $step => $chainling) |
|
31 | 31 | { |
32 | 32 | $this->search_and_execute_trait_methods($chainling); |
33 | - if(method_exists($this, $chainling) && empty($this->errors())) |
|
33 | + if (method_exists($this, $chainling) && empty($this->errors())) |
|
34 | 34 | { |
35 | 35 | $res = $this->$chainling(); |
36 | 36 | |
37 | - if($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution |
|
37 | + if ($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution |
|
38 | 38 | { |
39 | 39 | break; // dont go on with other |
40 | 40 | } |
41 | 41 | |
42 | - if($chainling === $method) |
|
42 | + if ($chainling === $method) |
|
43 | 43 | { |
44 | 44 | |
45 | 45 | $custom_template = $res; |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
50 | + if (method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
51 | 51 | $this->conclude(); |
52 | 52 | |
53 | - if(method_exists($this, 'display')) |
|
53 | + if (method_exists($this, 'display')) |
|
54 | 54 | $template = $this->display($custom_template); |
55 | 55 | } |
56 | 56 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | parent::prepare(); |
60 | 60 | |
61 | - if(!class_exists($this->model_class_name = $this->class_name())) |
|
61 | + if (!class_exists($this->model_class_name = $this->class_name())) |
|
62 | 62 | throw new \Exception("!class_exists($this->model_class_name)"); |
63 | 63 | |
64 | 64 | $this->model_type = $this->model_class_name::model_type(); |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | |
69 | 69 | $pk_values = []; |
70 | 70 | |
71 | - if($this->router()->submits()) |
|
71 | + if ($this->router()->submits()) |
|
72 | 72 | { |
73 | 73 | $this->form_model->import($this->sanitize_post_data($this->router()->submitted())); |
74 | 74 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted()); |
75 | 75 | |
76 | 76 | $this->load_model = $this->model_class_name::exists($pk_values); |
77 | 77 | } |
78 | - elseif($this->router()->requests()) |
|
78 | + elseif ($this->router()->requests()) |
|
79 | 79 | { |
80 | 80 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params()); |
81 | 81 | |
82 | - if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
82 | + if (!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
83 | 83 | $this->form_model = clone $this->load_model; |
84 | 84 | } |
85 | 85 | |
86 | - if(!is_null($this->load_model) && $this->load_model->traceable()) |
|
86 | + if (!is_null($this->load_model) && $this->load_model->traceable()) |
|
87 | 87 | $this->viewport('load_model_history', $this->load_model->traces() ?? []); |
88 | 88 | } |
89 | 89 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | // ----------- META ----------- |
95 | 95 | public function class_name() : string |
96 | 96 | { |
97 | - if(is_null($this->model_class_name)) |
|
97 | + if (is_null($this->model_class_name)) |
|
98 | 98 | { |
99 | 99 | $this->model_class_name = get_called_class(); |
100 | 100 | $this->model_class_name = str_replace('\Controllers\\', '\Models\\', $this->model_class_name); |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | public function persist_model($model) : ?ModelInterface |
108 | 108 | { |
109 | 109 | $this->errors = $model->save($this->operator()->operator_id(), $this->tracer()); // returns [errors] |
110 | - if(empty($this->errors())) |
|
110 | + if (empty($this->errors())) |
|
111 | 111 | { |
112 | 112 | $this->logger()->nice('CRUDITES_INSTANCE_ALTERED', ['MODEL_'.get_class($model)::model_type().'_INSTANCE']); |
113 | 113 | return $model; |
114 | 114 | } |
115 | - foreach($this->errors() as $field => $error_msg) |
|
115 | + foreach ($this->errors() as $field => $error_msg) |
|
116 | 116 | $this->logger()->warning($error_msg, [$field]); |
117 | 117 | |
118 | 118 | return null; |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | return $this->listing(); //default dashboard is a listing |
124 | 124 | } |
125 | 125 | |
126 | - public function listing($model=null,$filters=[],$options=[]) |
|
126 | + public function listing($model = null, $filters = [], $options = []) |
|
127 | 127 | { |
128 | 128 | $class_name = is_null($model) ? $this->model_class_name : get_class($model); |
129 | 129 | |
130 | - if(!isset($filters['date_start'])) $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
131 | - if(!isset($filters['date_stop'])) $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
130 | + if (!isset($filters['date_start'])) $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
131 | + if (!isset($filters['date_stop'])) $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
132 | 132 | |
133 | 133 | // dd($filters); |
134 | 134 | $listing = $class_name::filter($filters); |
@@ -139,24 +139,24 @@ discard block |
||
139 | 139 | public function viewport_listing($class_name, $listing, $listing_template) |
140 | 140 | { |
141 | 141 | $listing_fields = []; |
142 | - if(empty($listing)) |
|
142 | + if (empty($listing)) |
|
143 | 143 | { |
144 | - foreach($class_name::table()->columns() as $column) |
|
144 | + foreach ($class_name::table()->columns() as $column) |
|
145 | 145 | { |
146 | 146 | |
147 | - if(!$column->is_auto_incremented() && !$column->is_hidden()) |
|
148 | - $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
147 | + if (!$column->is_auto_incremented() && !$column->is_hidden()) |
|
148 | + $listing_fields[$column->name()] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
153 | 153 | $current = current($listing); |
154 | - if(is_object($current)) |
|
154 | + if (is_object($current)) |
|
155 | 155 | $current = get_object_vars($current); |
156 | 156 | |
157 | - foreach(array_keys($current) as $field) |
|
157 | + foreach (array_keys($current) as $field) |
|
158 | 158 | { |
159 | - $listing_fields[$field]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
159 | + $listing_fields[$field] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | } |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | $this->edit(); |
179 | 179 | } |
180 | 180 | |
181 | - public function edit(){} |
|
181 | + public function edit() {} |
|
182 | 182 | |
183 | 183 | public function save() |
184 | 184 | { |
185 | 185 | $model = $this->persist_model($this->form_model); |
186 | 186 | |
187 | - if(empty($this->errors())) |
|
187 | + if (empty($this->errors())) |
|
188 | 188 | $this->route_back($model); |
189 | 189 | else |
190 | 190 | { |
@@ -195,21 +195,21 @@ discard block |
||
195 | 195 | |
196 | 196 | public function before_edit() |
197 | 197 | { |
198 | - if(!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
198 | + if (!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
199 | 199 | { |
200 | 200 | $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_class_name::model_type().'_INSTANCE']); |
201 | 201 | $this->router()->hop($this->model_class_name::model_type()); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - public function before_save() : array { return [];} |
|
205 | + public function before_save() : array { return []; } |
|
206 | 206 | |
207 | 207 | // default: hop to altered object |
208 | - public function after_save() {$this->router()->hop($this->route_back());} |
|
208 | + public function after_save() {$this->router()->hop($this->route_back()); } |
|
209 | 209 | |
210 | 210 | public function destroy_confirm() |
211 | 211 | { |
212 | - if(is_null($this->load_model)) |
|
212 | + if (is_null($this->load_model)) |
|
213 | 213 | { |
214 | 214 | $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE']); |
215 | 215 | $this->router()->hop($this->model_type); |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | |
223 | 223 | public function before_destroy() // default: checks for load_model and immortality, hops back to object on failure |
224 | 224 | { |
225 | - if(is_null($this->load_model)) |
|
225 | + if (is_null($this->load_model)) |
|
226 | 226 | { |
227 | 227 | $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE']); |
228 | 228 | $this->router()->hop($this->model_type); |
229 | 229 | } |
230 | - elseif($this->load_model->immortal()) |
|
230 | + elseif ($this->load_model->immortal()) |
|
231 | 231 | { |
232 | 232 | |
233 | 233 | $this->logger()->warning('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', ['MODEL_'.$this->model_type.'_INSTANCE']); |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | |
238 | 238 | public function destroy() |
239 | 239 | { |
240 | - if(!$this->router()->submits()) |
|
240 | + if (!$this->router()->submits()) |
|
241 | 241 | throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
242 | 242 | |
243 | - if($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
243 | + if ($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
244 | 244 | { |
245 | 245 | $this->logger()->info('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model]); |
246 | 246 | $this->route_back($this->load_model); |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | |
264 | 264 | $this->viewport('form_model_type', $this->model_type); |
265 | 265 | |
266 | - if(isset($this->load_model)) |
|
266 | + if (isset($this->load_model)) |
|
267 | 267 | $this->viewport('load_model', $this->load_model); |
268 | 268 | |
269 | - if(isset($this->form_model)) |
|
269 | + if (isset($this->form_model)) |
|
270 | 270 | $this->viewport('form_model', $this->form_model); |
271 | 271 | } |
272 | 272 | |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | |
279 | 279 | $header = false; |
280 | 280 | |
281 | - foreach($collection as $line) |
|
281 | + foreach ($collection as $line) |
|
282 | 282 | { |
283 | 283 | $line = get_object_vars($line); |
284 | - if($header === false) |
|
284 | + if ($header === false) |
|
285 | 285 | { |
286 | - fputcsv($fp,array_keys($line)); |
|
286 | + fputcsv($fp, array_keys($line)); |
|
287 | 287 | $header = true; |
288 | 288 | } |
289 | - fputcsv($fp,$line); |
|
289 | + fputcsv($fp, $line); |
|
290 | 290 | } |
291 | 291 | fclose($fp); |
292 | 292 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | public function export() |
297 | 297 | { |
298 | 298 | $format = $this->router()->params('format'); |
299 | - switch($format) |
|
299 | + switch ($format) |
|
300 | 300 | { |
301 | 301 | case null: |
302 | 302 | $filename = $this->model_type; |
@@ -325,33 +325,33 @@ discard block |
||
325 | 325 | $route_params = []; |
326 | 326 | |
327 | 327 | $route_name = get_class($model)::model_type().'_'; |
328 | - if($model->is_new()) |
|
329 | - $route_name.= 'new'; |
|
328 | + if ($model->is_new()) |
|
329 | + $route_name .= 'new'; |
|
330 | 330 | else |
331 | 331 | { |
332 | - $route_name.= 'default'; |
|
332 | + $route_name .= 'default'; |
|
333 | 333 | $route_params = ['id' => $model->get_id()]; |
334 | 334 | } |
335 | 335 | $res = $this->router()->prehop($route_name, $route_params); |
336 | 336 | return $res; |
337 | 337 | } |
338 | 338 | |
339 | - public function route_factory($route=null, $route_params=[]) : string |
|
339 | + public function route_factory($route = null, $route_params = []) : string |
|
340 | 340 | { |
341 | - if(is_null($route) && $this->router()->submits()) |
|
341 | + if (is_null($route) && $this->router()->submits()) |
|
342 | 342 | $route = $this->form_model; |
343 | 343 | |
344 | - if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
344 | + if (!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
345 | 345 | $route = $this->route_model($route); |
346 | 346 | |
347 | 347 | return parent::route_factory($route, $route_params); |
348 | 348 | } |
349 | 349 | |
350 | - private function sanitize_post_data($post_data=[]) |
|
350 | + private function sanitize_post_data($post_data = []) |
|
351 | 351 | { |
352 | - foreach($this->model_class_name::table()->columns() as $col) |
|
352 | + foreach ($this->model_class_name::table()->columns() as $col) |
|
353 | 353 | { |
354 | - if($col->type()->is_boolean()) |
|
354 | + if ($col->type()->is_boolean()) |
|
355 | 355 | { |
356 | 356 | $post_data[$col->name()] = !empty($post_data[$col->name()]); |
357 | 357 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | $context['class'] = get_class($throwable); |
55 | 55 | $context['trace'] = $throwable->getTrace(); |
56 | 56 | |
57 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
57 | + if (is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
58 | 58 | (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
59 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
59 | + elseif (is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
60 | 60 | (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
61 | 61 | else |
62 | 62 | { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | public function system_halted($level) |
69 | 69 | { |
70 | - switch($level) |
|
70 | + switch ($level) |
|
71 | 71 | { |
72 | 72 | case LogLevel::ERROR: |
73 | 73 | case LogLevel::CRITICAL: |
@@ -86,19 +86,19 @@ discard block |
||
86 | 86 | $display_error = null; |
87 | 87 | |
88 | 88 | // --- Handles Throwables (exception_handler()) |
89 | - if($message==self::INTERNAL_ERROR || $message== self::USER_EXCEPTION) |
|
89 | + if ($message == self::INTERNAL_ERROR || $message == self::USER_EXCEPTION) |
|
90 | 90 | { |
91 | 91 | $this->has_halting_messages = true; |
92 | 92 | $display_error = \HexMakina\Debugger\Debugger::format_throwable_message($context['class'], $context['code'], $context['file'], $context['line'], $context['text']); |
93 | 93 | error_log($display_error); |
94 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
94 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
95 | 95 | self::HTTP_500($display_error); |
96 | 96 | } |
97 | - elseif($this->system_halted($level)) // analyses error level |
|
97 | + elseif ($this->system_halted($level)) // analyses error level |
|
98 | 98 | { |
99 | 99 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message); |
100 | 100 | error_log($display_error); |
101 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
101 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
102 | 102 | self::HTTP_500($display_error); |
103 | 103 | } |
104 | 104 | else |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | // ----------------------------------------------------------- User messages:add one |
151 | 151 | public function report_to_user($level, $message, $context = []) |
152 | 152 | { |
153 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
153 | + if (!isset($_SESSION[self::REPORTING_USER])) |
|
154 | 154 | $_SESSION[self::REPORTING_USER] = []; |
155 | 155 | |
156 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
156 | + if (!isset($_SESSION[self::REPORTING_USER][$level])) |
|
157 | 157 | $_SESSION[self::REPORTING_USER][$level] = []; |
158 | 158 | |
159 | 159 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
@@ -185,21 +185,21 @@ discard block |
||
185 | 185 | private static function map_error_level_to_log_level($level) : string |
186 | 186 | { |
187 | 187 | // http://php.net/manual/en/errorfunc.constants.php |
188 | - $m=[]; |
|
188 | + $m = []; |
|
189 | 189 | |
190 | - $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
191 | - $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
190 | + $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
191 | + $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
192 | 192 | |
193 | - $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
194 | - $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
193 | + $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
194 | + $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
195 | 195 | |
196 | - $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
197 | - $m[8]=$m[1024]=LogLevel::ERROR; |
|
196 | + $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
197 | + $m[8] = $m[1024] = LogLevel::ERROR; |
|
198 | 198 | |
199 | - $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
200 | - $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
199 | + $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
200 | + $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
201 | 201 | |
202 | - if(isset($m[$level])) |
|
202 | + if (isset($m[$level])) |
|
203 | 203 | return $m[$level]; |
204 | 204 | |
205 | 205 | throw new \Exception(__FUNCTION__."($level): $level is unknown"); |