@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | namespace HexMakina\kadro\Controllers; |
13 | 13 | |
14 | 14 | use \HexMakina\Crudites\Crudites; |
15 | -use \HexMakina\kadro\Auth\{Operator,OperatorInterface,ACL,AccessRefusedException}; |
|
15 | +use \HexMakina\kadro\Auth\{Operator, OperatorInterface, ACL, AccessRefusedException}; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | class OperatorController extends \HexMakina\kadro\Controllers\ORMController |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | parent::edit(); |
24 | 24 | |
25 | 25 | // do we create? or do we edit someone else ? must be admin |
26 | - if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
26 | + if (is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
27 | 27 | $this->authorize('group_admin'); |
28 | 28 | |
29 | 29 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | public function save() |
37 | 37 | { |
38 | - if($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
38 | + if ($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
39 | 39 | $this->authorize('group_admin'); |
40 | 40 | |
41 | 41 | parent::save(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function before_save() : array |
45 | 45 | { |
46 | 46 | //------------------------------------------------------------- PASSWORDS |
47 | - if($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
47 | + if ($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
48 | 48 | { |
49 | 49 | $this->logger()->warning(L('KADRO_operator_ERR_PASSWORDS_MISMATCH')); |
50 | 50 | return $this->edit(); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function dashboard() |
59 | 59 | { |
60 | 60 | $real_operator_class = get_class($this->operator()); |
61 | - $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null,'username', 'ASC']])); |
|
61 | + $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null, 'username', 'ASC']])); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function destroy() |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | parent::authorize('group_admin'); |
72 | 72 | |
73 | 73 | $operator = Operator::one($this->router()->params()); |
74 | - if($operator->username() == $this->operator()->username()) |
|
74 | + if ($operator->username() == $this->operator()->username()) |
|
75 | 75 | throw new AccessRefusedException(); |
76 | 76 | |
77 | - if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
77 | + if (Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
78 | 78 | { |
79 | 79 | $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED'; |
80 | 80 | $this->logger()->nice(L($confirmation_message, [$operator->name()])); |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | parent::authorize('group_admin'); |
93 | 93 | |
94 | 94 | $operator = Operator::one(['username' => $this->router()->params('username')]); |
95 | - if($operator->username() == $this->operator()->username()) |
|
95 | + if ($operator->username() == $this->operator()->username()) |
|
96 | 96 | throw new AccessRefusedException(); |
97 | 97 | |
98 | 98 | $permission_id = $this->router()->params('permission_id'); |
99 | 99 | |
100 | 100 | $row_data = ['operator_id' => $operator->operator_id(), 'permission_id' => $permission_id]; |
101 | 101 | $row = ACL::table()->restore($row_data); |
102 | - if($row->is_new()) |
|
102 | + if ($row->is_new()) |
|
103 | 103 | { |
104 | 104 | $row = ACL::table()->produce($row_data); |
105 | 105 | $res = $row->persist(); |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HexMakina\kadro\Controllers; |
4 | 4 | |
5 | -use HexMakina\kadro\Auth\{Operator,Permission,ACL}; |
|
6 | -use HexMakina\kadro\Auth\{OperatorInterface,AccessRefusedException}; |
|
5 | +use HexMakina\kadro\Auth\{Operator, Permission, ACL}; |
|
6 | +use HexMakina\kadro\Auth\{OperatorInterface, AccessRefusedException}; |
|
7 | 7 | |
8 | 8 | class ReceptionController extends KadroController |
9 | 9 | { |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | public function welcome(OperatorInterface $operator) |
16 | 16 | { |
17 | 17 | |
18 | - if($this->router()->name() === 'identify') |
|
18 | + if ($this->router()->name() === 'identify') |
|
19 | 19 | $this->identify($operator); |
20 | 20 | |
21 | 21 | $Controller = $this->router()->target_controller(); |
22 | 22 | $Controller = $this->box($Controller); |
23 | 23 | |
24 | 24 | |
25 | - if($Controller->requires_operator()) |
|
25 | + if ($Controller->requires_operator()) |
|
26 | 26 | { |
27 | - if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
27 | + if (is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
28 | 28 | $this->router()->hop('checkin'); |
29 | 29 | |
30 | - if(!$operator->is_active()) |
|
30 | + if (!$operator->is_active()) |
|
31 | 31 | { |
32 | 32 | $this->checkout(); |
33 | 33 | throw new AccessRefusedException(); |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | |
60 | 60 | $operator = get_class($op)::exists(['username' => $username]); |
61 | 61 | |
62 | - if(is_null($operator) || !$operator->is_active()) |
|
62 | + if (is_null($operator) || !$operator->is_active()) |
|
63 | 63 | throw new \Exception('ERR_DISABLED'); |
64 | 64 | |
65 | - if(!$operator->password_verify($password)) |
|
65 | + if (!$operator->password_verify($password)) |
|
66 | 66 | throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
67 | 67 | |
68 | 68 | $this->box('StateAgent')->operator_id($operator->get_id()); |
@@ -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 | $this->display($custom_template); // ret value ignored.. |
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) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
|
86 | + if (!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
|
87 | 87 | { |
88 | 88 | // $traces = $this->tracer()->traces_by_model($this->load_model); |
89 | 89 | $traces = $this->tracer()->history_by_model($this->load_model); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // ----------- META ----------- |
100 | 100 | public function class_name() : string |
101 | 101 | { |
102 | - if(is_null($this->model_class_name)) |
|
102 | + if (is_null($this->model_class_name)) |
|
103 | 103 | { |
104 | 104 | $this->model_class_name = get_called_class(); |
105 | 105 | $this->model_class_name = str_replace('\Controllers\\', '\Models\\', $this->model_class_name); |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | public function persist_model($model) : ?ModelInterface |
113 | 113 | { |
114 | 114 | $this->errors = $model->save($this->operator()->operator_id(), $this->tracer()); // returns [errors] |
115 | - if(empty($this->errors())) |
|
115 | + if (empty($this->errors())) |
|
116 | 116 | { |
117 | 117 | $this->logger()->nice(L('CRUDITES_INSTANCE_ALTERED', [L('MODEL_'.get_class($model)::model_type().'_INSTANCE')])); |
118 | 118 | return $model; |
119 | 119 | } |
120 | - foreach($this->errors() as $field => $error_msg) |
|
120 | + foreach ($this->errors() as $field => $error_msg) |
|
121 | 121 | $this->logger()->warning(L($error_msg, [$field])); |
122 | 122 | |
123 | 123 | return null; |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | return $this->listing(); //default dashboard is a listing |
129 | 129 | } |
130 | 130 | |
131 | - public function listing($model=null,$filters=[],$options=[]) |
|
131 | + public function listing($model = null, $filters = [], $options = []) |
|
132 | 132 | { |
133 | 133 | $class_name = is_null($model) ? $this->model_class_name : get_class($model); |
134 | 134 | |
135 | - if(!isset($filters['date_start'])) $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
136 | - if(!isset($filters['date_stop'])) $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
135 | + if (!isset($filters['date_start'])) $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
136 | + if (!isset($filters['date_stop'])) $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
137 | 137 | |
138 | 138 | // dd($filters); |
139 | 139 | $listing = $class_name::filter($filters); |
@@ -144,24 +144,24 @@ discard block |
||
144 | 144 | public function viewport_listing($class_name, $listing, $listing_template) |
145 | 145 | { |
146 | 146 | $listing_fields = []; |
147 | - if(empty($listing)) |
|
147 | + if (empty($listing)) |
|
148 | 148 | { |
149 | - foreach($class_name::table()->columns() as $column) |
|
149 | + foreach ($class_name::table()->columns() as $column) |
|
150 | 150 | { |
151 | 151 | |
152 | - if(!$column->is_auto_incremented() && !$column->is_hidden()) |
|
153 | - $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
152 | + if (!$column->is_auto_incremented() && !$column->is_hidden()) |
|
153 | + $listing_fields[$column->name()] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | else |
157 | 157 | { |
158 | 158 | $current = current($listing); |
159 | - if(is_object($current)) |
|
159 | + if (is_object($current)) |
|
160 | 160 | $current = get_object_vars($current); |
161 | 161 | |
162 | - foreach(array_keys($current) as $field) |
|
162 | + foreach (array_keys($current) as $field) |
|
163 | 163 | { |
164 | - $listing_fields[$field]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
164 | + $listing_fields[$field] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field)); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | } |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | $this->edit(); |
184 | 184 | } |
185 | 185 | |
186 | - public function edit(){} |
|
186 | + public function edit() {} |
|
187 | 187 | |
188 | 188 | public function save() |
189 | 189 | { |
190 | 190 | $model = $this->persist_model($this->form_model); |
191 | 191 | |
192 | - if(empty($this->errors())) |
|
192 | + if (empty($this->errors())) |
|
193 | 193 | $this->route_back($model); |
194 | 194 | else |
195 | 195 | { |
@@ -200,21 +200,21 @@ discard block |
||
200 | 200 | |
201 | 201 | public function before_edit() |
202 | 202 | { |
203 | - if(!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
203 | + if (!is_null($this->router()->params('id')) && is_null($this->load_model)) |
|
204 | 204 | { |
205 | 205 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', [L('MODEL_'.$this->model_class_name::model_type().'_INSTANCE')])); |
206 | 206 | $this->router()->hop($this->model_class_name::model_type()); |
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - public function before_save() : array { return [];} |
|
210 | + public function before_save() : array { return []; } |
|
211 | 211 | |
212 | 212 | // default: hop to altered object |
213 | - public function after_save() {$this->router()->hop($this->route_back());} |
|
213 | + public function after_save() {$this->router()->hop($this->route_back()); } |
|
214 | 214 | |
215 | 215 | public function destroy_confirm() |
216 | 216 | { |
217 | - if(is_null($this->load_model)) |
|
217 | + if (is_null($this->load_model)) |
|
218 | 218 | { |
219 | 219 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
220 | 220 | $this->router()->hop($this->model_type); |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | |
228 | 228 | public function before_destroy() // default: checks for load_model and immortality, hops back to object on failure |
229 | 229 | { |
230 | - if(is_null($this->load_model)) |
|
230 | + if (is_null($this->load_model)) |
|
231 | 231 | { |
232 | 232 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
233 | 233 | $this->router()->hop($this->model_type); |
234 | 234 | } |
235 | - elseif($this->load_model->immortal()) |
|
235 | + elseif ($this->load_model->immortal()) |
|
236 | 236 | { |
237 | 237 | |
238 | 238 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | |
243 | 243 | public function destroy() |
244 | 244 | { |
245 | - if(!$this->router()->submits()) |
|
245 | + if (!$this->router()->submits()) |
|
246 | 246 | throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
247 | 247 | |
248 | - if($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
248 | + if ($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
|
249 | 249 | { |
250 | 250 | $this->logger()->info(L('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model])); |
251 | 251 | $this->route_back($this->load_model); |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | |
269 | 269 | $this->viewport('form_model_type', $this->model_type); |
270 | 270 | |
271 | - if(isset($this->load_model)) |
|
271 | + if (isset($this->load_model)) |
|
272 | 272 | $this->viewport('load_model', $this->load_model); |
273 | 273 | |
274 | - if(isset($this->form_model)) |
|
274 | + if (isset($this->form_model)) |
|
275 | 275 | $this->viewport('form_model', $this->form_model); |
276 | 276 | } |
277 | 277 | |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | |
284 | 284 | $header = false; |
285 | 285 | |
286 | - foreach($collection as $line) |
|
286 | + foreach ($collection as $line) |
|
287 | 287 | { |
288 | 288 | $line = get_object_vars($line); |
289 | - if($header === false) |
|
289 | + if ($header === false) |
|
290 | 290 | { |
291 | - fputcsv($fp,array_keys($line)); |
|
291 | + fputcsv($fp, array_keys($line)); |
|
292 | 292 | $header = true; |
293 | 293 | } |
294 | - fputcsv($fp,$line); |
|
294 | + fputcsv($fp, $line); |
|
295 | 295 | } |
296 | 296 | fclose($fp); |
297 | 297 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | public function export() |
302 | 302 | { |
303 | 303 | $format = $this->router()->params('format'); |
304 | - switch($format) |
|
304 | + switch ($format) |
|
305 | 305 | { |
306 | 306 | case null: |
307 | 307 | $filename = $this->model_type; |
@@ -330,33 +330,33 @@ discard block |
||
330 | 330 | $route_params = []; |
331 | 331 | |
332 | 332 | $route_name = get_class($model)::model_type().'_'; |
333 | - if($model->is_new()) |
|
334 | - $route_name.= 'new'; |
|
333 | + if ($model->is_new()) |
|
334 | + $route_name .= 'new'; |
|
335 | 335 | else |
336 | 336 | { |
337 | - $route_name.= 'default'; |
|
337 | + $route_name .= 'default'; |
|
338 | 338 | $route_params = ['id' => $model->get_id()]; |
339 | 339 | } |
340 | 340 | $res = $this->router()->prehop($route_name, $route_params); |
341 | 341 | return $res; |
342 | 342 | } |
343 | 343 | |
344 | - public function route_factory($route=null, $route_params=[]) : string |
|
344 | + public function route_factory($route = null, $route_params = []) : string |
|
345 | 345 | { |
346 | - if(is_null($route) && $this->router()->submits()) |
|
346 | + if (is_null($route) && $this->router()->submits()) |
|
347 | 347 | $route = $this->form_model; |
348 | 348 | |
349 | - if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
349 | + if (!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
350 | 350 | $route = $this->route_model($route); |
351 | 351 | |
352 | 352 | return parent::route_factory($route, $route_params); |
353 | 353 | } |
354 | 354 | |
355 | - private function sanitize_post_data($post_data=[]) |
|
355 | + private function sanitize_post_data($post_data = []) |
|
356 | 356 | { |
357 | - foreach($this->model_class_name::table()->columns() as $col) |
|
357 | + foreach ($this->model_class_name::table()->columns() as $col) |
|
358 | 358 | { |
359 | - if($col->type()->is_boolean()) |
|
359 | + if ($col->type()->is_boolean()) |
|
360 | 360 | { |
361 | 361 | $post_data[$col->name()] = !empty($post_data[$col->name()]); |
362 | 362 | } |
@@ -13,17 +13,17 @@ |
||
13 | 13 | public function match($requestUrl = null, $requestMethod = null); |
14 | 14 | |
15 | 15 | // generates URL for href and location |
16 | - public function prehop($route, $route_params=[]); |
|
16 | + public function prehop($route, $route_params = []); |
|
17 | 17 | |
18 | 18 | // heads to another location |
19 | - public function hop($route, $route_params=[]); |
|
19 | + public function hop($route, $route_params = []); |
|
20 | 20 | |
21 | 21 | // do you GET it ? |
22 | 22 | public function requests() : bool; |
23 | 23 | |
24 | 24 | // have you POSTed it ? |
25 | 25 | public function submits() : bool; |
26 | - public function submitted($param_name=null); |
|
26 | + public function submitted($param_name = null); |
|
27 | 27 | |
28 | 28 | public function send_file($file_path); |
29 | 29 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | public function __debugInfo() : array |
17 | 17 | { |
18 | 18 | $dbg = get_object_vars($this); |
19 | - $dbg['configurations']['template_engine'] = isset($dbg['configurations']['template_engine'])? get_class($dbg['configurations']['template_engine']) : 'NOT SET'; |
|
19 | + $dbg['configurations']['template_engine'] = isset($dbg['configurations']['template_engine']) ? get_class($dbg['configurations']['template_engine']) : 'NOT SET'; |
|
20 | 20 | |
21 | 21 | return $dbg; |
22 | 22 | } |
@@ -34,45 +34,45 @@ discard block |
||
34 | 34 | public function get($configuration) |
35 | 35 | { |
36 | 36 | |
37 | - if(!is_string($configuration)) |
|
37 | + if (!is_string($configuration)) |
|
38 | 38 | throw new LamentException($configuration); |
39 | 39 | |
40 | - if($this->has($configuration)) |
|
40 | + if ($this->has($configuration)) |
|
41 | 41 | return $this->configurations[$configuration]; |
42 | 42 | |
43 | 43 | |
44 | 44 | // fallbacks |
45 | - if(preg_match('/^settings\./', $configuration, $m) === 1) |
|
45 | + if (preg_match('/^settings\./', $configuration, $m) === 1) |
|
46 | 46 | { |
47 | 47 | $ret = $this->configurations; |
48 | - foreach(explode('.', $configuration) as $k) |
|
48 | + foreach (explode('.', $configuration) as $k) |
|
49 | 49 | { |
50 | - if(!isset($ret[$k])) |
|
50 | + if (!isset($ret[$k])) |
|
51 | 51 | throw new ConfigurationException($configuration); |
52 | 52 | $ret = $ret[$k]; |
53 | 53 | } |
54 | 54 | |
55 | 55 | return $ret; |
56 | 56 | } |
57 | - elseif(class_exists($configuration)) // auto create instances |
|
57 | + elseif (class_exists($configuration)) // auto create instances |
|
58 | 58 | { |
59 | 59 | |
60 | 60 | $rc = new \ReflectionClass($configuration); |
61 | 61 | |
62 | 62 | $construction_args = []; |
63 | 63 | $instance = null; |
64 | - if(!is_null($rc->getConstructor())) |
|
64 | + if (!is_null($rc->getConstructor())) |
|
65 | 65 | { |
66 | - foreach($rc->getConstructor()->getParameters() as $param) |
|
66 | + foreach ($rc->getConstructor()->getParameters() as $param) |
|
67 | 67 | { |
68 | - $construction_args []= $this->get($param->getType().''); |
|
68 | + $construction_args [] = $this->get($param->getType().''); |
|
69 | 69 | } |
70 | 70 | $instance = $rc->newInstanceArgs($construction_args); |
71 | 71 | } |
72 | 72 | else |
73 | 73 | $instance = $rc->newInstanceArgs(); |
74 | 74 | |
75 | - if($rc->hasMethod('set_container')) |
|
75 | + if ($rc->hasMethod('set_container')) |
|
76 | 76 | $instance->set_container($this); |
77 | 77 | |
78 | 78 | return $instance; |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace HexMakina\kadro\Auth; |
3 | -class AccessRefusedException extends \Exception{} |
|
3 | +class AccessRefusedException extends \Exception {} |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | |
18 | 18 | public function load_operator($id = null) |
19 | 19 | { |
20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
20 | + if (!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
21 | 21 | $this->operator = Operator::exists($operator_id); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function operator() : ?OperatorInterface |
25 | 25 | { |
26 | - if(is_null($this->operator)) |
|
26 | + if (is_null($this->operator)) |
|
27 | 27 | { |
28 | 28 | $extract_attempt = $this->extract(new Operator(), true); |
29 | - if(!is_null($extract_attempt)) |
|
29 | + if (!is_null($extract_attempt)) |
|
30 | 30 | { |
31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
32 | - if(property_exists($this, $permission_marker)) |
|
31 | + foreach (['permission_names', 'permission_ids'] as $permission_marker) |
|
32 | + if (property_exists($this, $permission_marker)) |
|
33 | 33 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
34 | 34 | |
35 | 35 | $this->operator = $extract_attempt; |
@@ -45,23 +45,23 @@ discard block |
||
45 | 45 | |
46 | 46 | public static function enhance_query_retrieve($Query, $filters, $options) |
47 | 47 | { |
48 | - $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
48 | + $joined_alias = $Query->auto_join([ACL::table(), 'ACL'], null, 'LEFT OUTER'); |
|
49 | 49 | $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
50 | 50 | |
51 | 51 | $permission_ids_and_names = []; |
52 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
53 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
52 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
53 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
54 | 54 | $Query->select_also($permission_ids_and_names); |
55 | 55 | |
56 | 56 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
57 | 57 | |
58 | - if(isset($filters['username'])) |
|
58 | + if (isset($filters['username'])) |
|
59 | 59 | $Query->aw_eq('username', $filters['username'], 'operator'); |
60 | 60 | |
61 | - if(isset($filters['email'])) |
|
61 | + if (isset($filters['email'])) |
|
62 | 62 | $Query->aw_eq('email', $filters['email'], 'operator'); |
63 | 63 | |
64 | - if(isset($filters['active'])) |
|
64 | + if (isset($filters['active'])) |
|
65 | 65 | $Query->aw_eq('active', $filters['active'], 'operator'); |
66 | 66 | |
67 | 67 | return $Query; |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | return in_array($permission_name, self::permissions_names_for($op)); |
19 | 19 | } |
20 | 20 | |
21 | - public static function query_retrieve($filters=[], $options=[]) : SelectInterface |
|
21 | + public static function query_retrieve($filters = [], $options = []) : SelectInterface |
|
22 | 22 | { |
23 | 23 | $options['eager'] = false; |
24 | - $ret = parent::query_retrieve($filters,$options); |
|
24 | + $ret = parent::query_retrieve($filters, $options); |
|
25 | 25 | $eager_params = []; |
26 | - $eager_params[Permission::table_name()]=Permission::table_alias(); |
|
27 | - $eager_params[Operator::table_name()]=Operator::table_alias(); |
|
28 | - $eager_params[ACL::table_name()]=ACL::table_alias(); |
|
26 | + $eager_params[Permission::table_name()] = Permission::table_alias(); |
|
27 | + $eager_params[Operator::table_name()] = Operator::table_alias(); |
|
28 | + $eager_params[ACL::table_name()] = ACL::table_alias(); |
|
29 | 29 | |
30 | 30 | $ret->eager($eager_params); |
31 | 31 | |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | $res = self::any(['operator_id'=>$op->operator_id()]); |
38 | 38 | |
39 | 39 | $permission_ids = []; |
40 | - foreach($res as $r) |
|
41 | - $permission_ids[]=$r->get('permission_id'); |
|
40 | + foreach ($res as $r) |
|
41 | + $permission_ids[] = $r->get('permission_id'); |
|
42 | 42 | |
43 | 43 | $ret = Permission::filter(['ids'=>$permission_ids]); |
44 | 44 | return $ret; |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | { |
49 | 49 | $operator_with_perms = get_class($op)::exists($op->operator_id()); |
50 | 50 | // $operator_with_perms = get_class($op)::retrieve($operator_with_perms); |
51 | - if(is_null($operator_with_perms)) |
|
51 | + if (is_null($operator_with_perms)) |
|
52 | 52 | return []; |
53 | 53 | |
54 | - return explode(',',$operator_with_perms->get('permission_names')); |
|
54 | + return explode(',', $operator_with_perms->get('permission_names')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | public static function allow_in(OperatorInterface $op, Permission $p) |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | return $this->get('language_code'); |
67 | 67 | } |
68 | 68 | |
69 | - public static function query_retrieve($filters=[], $options=[]) : SelectInterface |
|
69 | + public static function query_retrieve($filters = [], $options = []) : SelectInterface |
|
70 | 70 | { |
71 | 71 | $Query = static::table()->select(); |
72 | - if(isset($options['eager']) && $options['eager'] === true) |
|
72 | + if (isset($options['eager']) && $options['eager'] === true) |
|
73 | 73 | { |
74 | 74 | $Query->group_by('id'); |
75 | 75 | |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | $Query->select_also(["GROUP_CONCAT(DISTINCT kadro_permission.id) as permission_ids", "GROUP_CONCAT(DISTINCT kadro_permission.name) as permission_names"]); |
79 | 79 | } |
80 | 80 | |
81 | - if(isset($filters['model']) && !empty($filters['model'])) |
|
81 | + if (isset($filters['model']) && !empty($filters['model'])) |
|
82 | 82 | { |
83 | - $Query->join([static::otm('t'), static::otm('a')],[[static::otm('a'),static::otm('k'), 't_from','id']], 'INNER'); |
|
83 | + $Query->join([static::otm('t'), static::otm('a')], [[static::otm('a'), static::otm('k'), 't_from', 'id']], 'INNER'); |
|
84 | 84 | $Query->aw_fields_eq(['model_id' => $filters['model']->get_id(), 'model_type' => get_class($filters['model'])::model_type()], static::otm('a')); |
85 | 85 | } |
86 | 86 |