@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | public function welcome(OperatorInterface $operator) |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - if($this->router()->name() === 'identify') |
|
| 22 | - $this->identify($operator); |
|
| 21 | + if($this->router()->name() === 'identify') { |
|
| 22 | + $this->identify($operator); |
|
| 23 | + } |
|
| 23 | 24 | |
| 24 | 25 | $Controller = $this->router()->target_controller(); |
| 25 | 26 | $Controller = $this->box($Controller); |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | |
| 28 | 29 | if($Controller->requires_operator()) |
| 29 | 30 | { |
| 30 | - if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) |
|
| 31 | - $this->router()->hop('checkin'); |
|
| 31 | + if(is_null($operator = get_class($operator)::exists($this->box('StateAgent')->operator_id()))) { |
|
| 32 | + $this->router()->hop('checkin'); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | if(!$operator->is_active()) |
| 34 | 36 | { |
@@ -62,11 +64,13 @@ discard block |
||
| 62 | 64 | |
| 63 | 65 | $operator = get_class($op)::exists(['username' => $username]); |
| 64 | 66 | |
| 65 | - if(is_null($operator) || !$operator->is_active()) |
|
| 66 | - throw new \Exception('ERR_DISABLED'); |
|
| 67 | + if(is_null($operator) || !$operator->is_active()) { |
|
| 68 | + throw new \Exception('ERR_DISABLED'); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | - if(!$operator->password_verify($password)) |
|
| 69 | - throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
|
| 71 | + if(!$operator->password_verify($password)) { |
|
| 72 | + throw new \Exception('ERR_WRONG_LOGIN_OR_PASSWORD'); |
|
| 73 | + } |
|
| 70 | 74 | |
| 71 | 75 | $this->box('StateAgent')->operator_id($operator->get_id()); |
| 72 | 76 | $this->logger()->nice(L('PAGE_CHECKIN_WELCOME', [$operator->name()])); |
@@ -92,8 +92,9 @@ discard block |
||
| 92 | 92 | //--------------------------------------------------------------- ŝablonoj |
| 93 | 93 | require_once 'smarty/smarty/libs/Smarty.class.php'; |
| 94 | 94 | // Load smarty template parser |
| 95 | - if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) |
|
| 96 | - throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); |
|
| 95 | + if(is_null($box->get('settings.smarty.template_path')) || is_null($box->get('settings.smarty.compiled_path'))) { |
|
| 96 | + throw new \Exception("SMARTY CONFIG ERROR: missing parameters"); |
|
| 97 | + } |
|
| 97 | 98 | |
| 98 | 99 | $smarty=new \Smarty(); |
| 99 | 100 | $box->register('template_engine', $smarty); |
@@ -124,7 +125,8 @@ discard block |
||
| 124 | 125 | $lezer->init(); |
| 125 | 126 | |
| 126 | 127 | $smarty->assign('language', $language); |
| 127 | - if($cookies_enabled === true) |
|
| 128 | - setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); |
|
| 128 | + if($cookies_enabled === true) { |
|
| 129 | + setcookie('lang', $language, time()+(365 * 24 * 60 * 60), "/", ""); |
|
| 130 | + } |
|
| 129 | 131 | |
| 130 | 132 | } |
@@ -11,18 +11,16 @@ discard block |
||
| 11 | 11 | if(property_exists($this, 'permission_names')) |
| 12 | 12 | { |
| 13 | 13 | return explode(',', $this->permission_names); |
| 14 | - } |
|
| 15 | - elseif(property_exists($this, 'permission_ids')) |
|
| 14 | + } elseif(property_exists($this, 'permission_ids')) |
|
| 16 | 15 | { |
| 17 | 16 | $ids = explode(',', $this->permission_ids); |
| 18 | 17 | $ret = []; |
| 19 | 18 | $permissions = Permission::get_many_by_AIPK($ids); |
| 20 | - foreach($permissions as $id => $p) |
|
| 21 | - $ret[]="$p"; |
|
| 19 | + foreach($permissions as $id => $p) { |
|
| 20 | + $ret[]="$p"; |
|
| 21 | + } |
|
| 22 | 22 | return $ret; |
| 23 | - } |
|
| 24 | - |
|
| 25 | - else |
|
| 23 | + } else |
|
| 26 | 24 | { |
| 27 | 25 | return ACL::permissions_names_for($this); |
| 28 | 26 | } |
@@ -31,21 +29,20 @@ discard block |
||
| 31 | 29 | public function permissions() |
| 32 | 30 | { |
| 33 | 31 | |
| 34 | - if(!is_null($this->permissions)) |
|
| 35 | - return $this->permissions; |
|
| 32 | + if(!is_null($this->permissions)) { |
|
| 33 | + return $this->permissions; |
|
| 34 | + } |
|
| 36 | 35 | $permission_unique_keys = null; |
| 37 | 36 | if(property_exists($this, 'permission_names')) |
| 38 | 37 | { |
| 39 | 38 | $permission_unique_keys = explode(',', $this->permission_names); |
| 40 | 39 | // vd(Permission::table()->select()); |
| 41 | 40 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
| 42 | - } |
|
| 43 | - elseif(property_exists($this, 'permission_ids')) |
|
| 41 | + } elseif(property_exists($this, 'permission_ids')) |
|
| 44 | 42 | { |
| 45 | 43 | $permission_unique_keys = explode(',', $this->permission_ids); |
| 46 | 44 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
| 47 | - } |
|
| 48 | - else |
|
| 45 | + } else |
|
| 49 | 46 | { |
| 50 | 47 | $this->permissions = ACL::permissions_for($this); |
| 51 | 48 | } |
@@ -56,39 +53,36 @@ discard block |
||
| 56 | 53 | public function has_permission($p) : bool |
| 57 | 54 | { |
| 58 | 55 | // new instances or inactive operators, none shall pass |
| 59 | - if($this->is_new() === true || $this->is_active() === false) |
|
| 60 | - return false; |
|
| 56 | + if($this->is_new() === true || $this->is_active() === false) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 61 | 59 | |
| 62 | 60 | $permission_name = $permission_id = null; |
| 63 | 61 | if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
| 64 | 62 | { |
| 65 | 63 | $permission_name = $p->get('name'); |
| 66 | 64 | $permission_id = $p->get_id(); |
| 65 | + } elseif(preg_match('/[0-9]+/', $p)) { |
|
| 66 | + $permission_id = $p; |
|
| 67 | + } else { |
|
| 68 | + $permission_name = $p; |
|
| 67 | 69 | } |
| 68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
| 69 | - $permission_id = $p; |
|
| 70 | - else |
|
| 71 | - $permission_name = $p; |
|
| 72 | 70 | |
| 73 | 71 | if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
| 74 | 72 | { |
| 75 | 73 | return strpos($this->get('permission_names'), $permission_name) !== false; |
| 76 | - } |
|
| 77 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 74 | + } elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 78 | 75 | { |
| 79 | 76 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
| 80 | - } |
|
| 81 | - elseif(!is_null($permission_name)) |
|
| 77 | + } elseif(!is_null($permission_name)) |
|
| 82 | 78 | { |
| 83 | 79 | if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
| 84 | 80 | { |
| 85 | 81 | return true; |
| 86 | - } |
|
| 87 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 82 | + } elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 88 | 83 | { |
| 89 | 84 | return true; |
| 90 | - } |
|
| 91 | - elseif(ACL::match($this, $permission_name) === true) |
|
| 85 | + } elseif(ACL::match($this, $permission_name) === true) |
|
| 92 | 86 | { |
| 93 | 87 | return true; |
| 94 | 88 | } |
@@ -34,9 +34,12 @@ discard block |
||
| 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()) { |
|
| 38 | + // logger handled a critical error during the chailing execution |
|
| 38 | 39 | { |
| 39 | - break; // dont go on with other |
|
| 40 | + break; |
|
| 41 | + } |
|
| 42 | + // dont go on with other |
|
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | if($chainling === $method) |
@@ -47,19 +50,24 @@ discard block |
||
| 47 | 50 | } |
| 48 | 51 | } |
| 49 | 52 | |
| 50 | - if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages |
|
| 53 | + if(method_exists($this, 'conclude')) { |
|
| 54 | + // conclude always executed, even with has_halting_messages |
|
| 51 | 55 | $this->conclude(); |
| 56 | + } |
|
| 52 | 57 | |
| 53 | - if(method_exists($this, 'display')) |
|
| 54 | - $this->display($custom_template); // ret value ignored.. |
|
| 58 | + if(method_exists($this, 'display')) { |
|
| 59 | + $this->display($custom_template); |
|
| 60 | + } |
|
| 61 | + // ret value ignored.. |
|
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | public function prepare() |
| 58 | 65 | { |
| 59 | 66 | parent::prepare(); |
| 60 | 67 | |
| 61 | - if(!class_exists($this->model_class_name = $this->class_name())) |
|
| 62 | - throw new \Exception("!class_exists($this->model_class_name)"); |
|
| 68 | + if(!class_exists($this->model_class_name = $this->class_name())) { |
|
| 69 | + throw new \Exception("!class_exists($this->model_class_name)"); |
|
| 70 | + } |
|
| 63 | 71 | |
| 64 | 72 | $this->model_type = $this->model_class_name::model_type(); |
| 65 | 73 | |
@@ -74,13 +82,13 @@ discard block |
||
| 74 | 82 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted()); |
| 75 | 83 | |
| 76 | 84 | $this->load_model = $this->model_class_name::exists($pk_values); |
| 77 | - } |
|
| 78 | - elseif($this->router()->requests()) |
|
| 85 | + } elseif($this->router()->requests()) |
|
| 79 | 86 | { |
| 80 | 87 | $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params()); |
| 81 | 88 | |
| 82 | - if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) |
|
| 83 | - $this->form_model = clone $this->load_model; |
|
| 89 | + if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) { |
|
| 90 | + $this->form_model = clone $this->load_model; |
|
| 91 | + } |
|
| 84 | 92 | } |
| 85 | 93 | |
| 86 | 94 | if(!is_null($this->load_model) && is_subclass_of($this->load_model, '\HexMakina\Crudites\Interfaces\TraceableInterface') && $this->load_model->traceable()) |
@@ -117,8 +125,9 @@ discard block |
||
| 117 | 125 | $this->logger()->nice(L('CRUDITES_INSTANCE_ALTERED', [L('MODEL_'.get_class($model)::model_type().'_INSTANCE')])); |
| 118 | 126 | return $model; |
| 119 | 127 | } |
| 120 | - foreach($this->errors() as $field => $error_msg) |
|
| 121 | - $this->logger()->warning(L($error_msg, [$field])); |
|
| 128 | + foreach($this->errors() as $field => $error_msg) { |
|
| 129 | + $this->logger()->warning(L($error_msg, [$field])); |
|
| 130 | + } |
|
| 122 | 131 | |
| 123 | 132 | return null; |
| 124 | 133 | } |
@@ -132,8 +141,12 @@ discard block |
||
| 132 | 141 | { |
| 133 | 142 | $class_name = is_null($model) ? $this->model_class_name : get_class($model); |
| 134 | 143 | |
| 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'); |
|
| 144 | + if(!isset($filters['date_start'])) { |
|
| 145 | + $filters['date_start'] = $this->box('StateAgent')->filters('date_start'); |
|
| 146 | + } |
|
| 147 | + if(!isset($filters['date_stop'])) { |
|
| 148 | + $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop'); |
|
| 149 | + } |
|
| 137 | 150 | |
| 138 | 151 | // dd($filters); |
| 139 | 152 | $listing = $class_name::filter($filters); |
@@ -149,15 +162,16 @@ discard block |
||
| 149 | 162 | foreach($class_name::table()->columns() as $column) |
| 150 | 163 | { |
| 151 | 164 | |
| 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())); |
|
| 165 | + if(!$column->is_auto_incremented() && !$column->is_hidden()) { |
|
| 166 | + $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name())); |
|
| 167 | + } |
|
| 154 | 168 | } |
| 155 | - } |
|
| 156 | - else |
|
| 169 | + } else |
|
| 157 | 170 | { |
| 158 | 171 | $current = current($listing); |
| 159 | - if(is_object($current)) |
|
| 160 | - $current = get_object_vars($current); |
|
| 172 | + if(is_object($current)) { |
|
| 173 | + $current = get_object_vars($current); |
|
| 174 | + } |
|
| 161 | 175 | |
| 162 | 176 | foreach(array_keys($current) as $field) |
| 163 | 177 | { |
@@ -189,9 +203,9 @@ discard block |
||
| 189 | 203 | { |
| 190 | 204 | $model = $this->persist_model($this->form_model); |
| 191 | 205 | |
| 192 | - if(empty($this->errors())) |
|
| 193 | - $this->route_back($model); |
|
| 194 | - else |
|
| 206 | + if(empty($this->errors())) { |
|
| 207 | + $this->route_back($model); |
|
| 208 | + } else |
|
| 195 | 209 | { |
| 196 | 210 | $this->edit(); |
| 197 | 211 | return 'edit'; |
@@ -231,8 +245,7 @@ discard block |
||
| 231 | 245 | { |
| 232 | 246 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_NOT_FOUND', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
| 233 | 247 | $this->router()->hop($this->model_type); |
| 234 | - } |
|
| 235 | - elseif($this->load_model->immortal()) |
|
| 248 | + } elseif($this->load_model->immortal()) |
|
| 236 | 249 | { |
| 237 | 250 | |
| 238 | 251 | $this->logger()->warning(L('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
@@ -242,15 +255,15 @@ discard block |
||
| 242 | 255 | |
| 243 | 256 | public function destroy() |
| 244 | 257 | { |
| 245 | - if(!$this->router()->submits()) |
|
| 246 | - throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
|
| 258 | + if(!$this->router()->submits()) { |
|
| 259 | + throw new \Exception('KADRO_ROUTER_MUST_SUBMIT'); |
|
| 260 | + } |
|
| 247 | 261 | |
| 248 | 262 | if($this->load_model->destroy($this->operator()->operator_id(), $this->tracer()) === false) |
| 249 | 263 | { |
| 250 | 264 | $this->logger()->info(L('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model])); |
| 251 | 265 | $this->route_back($this->load_model); |
| 252 | - } |
|
| 253 | - else |
|
| 266 | + } else |
|
| 254 | 267 | { |
| 255 | 268 | $this->logger()->nice(L('CRUDITES_INSTANCE_DESTROYED', [L('MODEL_'.$this->model_type.'_INSTANCE')])); |
| 256 | 269 | $this->route_back($this->model_type); |
@@ -268,11 +281,13 @@ discard block |
||
| 268 | 281 | |
| 269 | 282 | $this->viewport('form_model_type', $this->model_type); |
| 270 | 283 | |
| 271 | - if(isset($this->load_model)) |
|
| 272 | - $this->viewport('load_model', $this->load_model); |
|
| 284 | + if(isset($this->load_model)) { |
|
| 285 | + $this->viewport('load_model', $this->load_model); |
|
| 286 | + } |
|
| 273 | 287 | |
| 274 | - if(isset($this->form_model)) |
|
| 275 | - $this->viewport('form_model', $this->form_model); |
|
| 288 | + if(isset($this->form_model)) { |
|
| 289 | + $this->viewport('form_model', $this->form_model); |
|
| 290 | + } |
|
| 276 | 291 | } |
| 277 | 292 | |
| 278 | 293 | public function collection_to_csv($collection, $filename) |
@@ -330,9 +345,9 @@ discard block |
||
| 330 | 345 | $route_params = []; |
| 331 | 346 | |
| 332 | 347 | $route_name = get_class($model)::model_type().'_'; |
| 333 | - if($model->is_new()) |
|
| 334 | - $route_name.= 'new'; |
|
| 335 | - else |
|
| 348 | + if($model->is_new()) { |
|
| 349 | + $route_name.= 'new'; |
|
| 350 | + } else |
|
| 336 | 351 | { |
| 337 | 352 | $route_name.= 'default'; |
| 338 | 353 | $route_params = ['id' => $model->get_id()]; |
@@ -343,11 +358,13 @@ discard block |
||
| 343 | 358 | |
| 344 | 359 | public function route_factory($route=null, $route_params=[]) : string |
| 345 | 360 | { |
| 346 | - if(is_null($route) && $this->router()->submits()) |
|
| 347 | - $route = $this->form_model; |
|
| 361 | + if(is_null($route) && $this->router()->submits()) { |
|
| 362 | + $route = $this->form_model; |
|
| 363 | + } |
|
| 348 | 364 | |
| 349 | - if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) |
|
| 350 | - $route = $this->route_model($route); |
|
| 365 | + if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) { |
|
| 366 | + $route = $this->route_model($route); |
|
| 367 | + } |
|
| 351 | 368 | |
| 352 | 369 | return parent::route_factory($route, $route_params); |
| 353 | 370 | } |
@@ -37,8 +37,9 @@ 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 | 44 | $ret = Permission::filter(['ids'=>$permission_ids]); |
| 44 | 45 | return $ret; |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $operator_with_perms = get_class($op)::exists($op->operator_id()); |
| 49 | 50 | // $operator_with_perms = get_class($op)::retrieve($operator_with_perms); |
| 50 | - if(is_null($operator_with_perms)) |
|
| 51 | - return []; |
|
| 51 | + if(is_null($operator_with_perms)) { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | return explode(',',$operator_with_perms->get('permission_names')); |
| 54 | 56 | } |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | //----------------------------------------------------------- INITIALISATION |
| 18 | 18 | public function __construct($settings) |
| 19 | 19 | { |
| 20 | - if(!isset($settings['route_home'])) |
|
| 21 | - throw new RouterException('ROUTE_HOME_UNDEFINED'); |
|
| 20 | + if(!isset($settings['route_home'])) { |
|
| 21 | + throw new RouterException('ROUTE_HOME_UNDEFINED'); |
|
| 22 | + } |
|
| 22 | 23 | |
| 23 | 24 | parent::__construct(); |
| 24 | 25 | |
@@ -44,13 +45,15 @@ discard block |
||
| 44 | 45 | { |
| 45 | 46 | $this->match = parent::match($requestUrl, $requestMethod); |
| 46 | 47 | |
| 47 | - if($this->match === false) |
|
| 48 | - throw new RouterException('ROUTE_MATCH_FALSE'); |
|
| 48 | + if($this->match === false) { |
|
| 49 | + throw new RouterException('ROUTE_MATCH_FALSE'); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | $res = explode('::', self::target()); |
| 51 | 53 | |
| 52 | - if($res === false || !isset($res[1]) || isset($ret[2])) |
|
| 53 | - throw new RouterException('INVALID_TARGET'); |
|
| 54 | + if($res === false || !isset($res[1]) || isset($ret[2])) { |
|
| 55 | + throw new RouterException('INVALID_TARGET'); |
|
| 56 | + } |
|
| 54 | 57 | |
| 55 | 58 | // if($this->match['name'] === 'akadok_controller_method') |
| 56 | 59 | // $res = [ucfirst(self::params('controller')).'Controller', ucfirst(self::params('method'))]; |
@@ -60,12 +63,14 @@ discard block |
||
| 60 | 63 | $target_method = $res[1]; |
| 61 | 64 | $found = false; |
| 62 | 65 | |
| 63 | - foreach($this->controller_namespaces as $controller_ns) |
|
| 64 | - if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
| 66 | + foreach($this->controller_namespaces as $controller_ns) { |
|
| 67 | + if($found = class_exists($controller_class_name = "$controller_ns$target_controller")) |
|
| 65 | 68 | break; |
| 69 | + } |
|
| 66 | 70 | |
| 67 | - if($found === false) |
|
| 68 | - throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
| 71 | + if($found === false) { |
|
| 72 | + throw new RouterException('INVALID_CONTROLLER_NAME'); |
|
| 73 | + } |
|
| 69 | 74 | |
| 70 | 75 | $this->match['target_controller'] = $controller_class_name; |
| 71 | 76 | $this->match['target_method'] = $target_method; |
@@ -87,16 +92,19 @@ discard block |
||
| 87 | 92 | { |
| 88 | 93 | |
| 89 | 94 | // $key is null, returns $dat_ass or empty array |
| 90 | - if(is_null($key)) |
|
| 91 | - return $dat_ass ?? []; |
|
| 95 | + if(is_null($key)) { |
|
| 96 | + return $dat_ass ?? []; |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | 99 | // $dat_ass[$key] not set, returns null |
| 94 | - if(!isset($dat_ass[$key])) |
|
| 95 | - return null; |
|
| 100 | + if(!isset($dat_ass[$key])) { |
|
| 101 | + return null; |
|
| 102 | + } |
|
| 96 | 103 | |
| 97 | 104 | // $dat_ass[$key] is a string, returns decoded value |
| 98 | - if(is_string($dat_ass[$key])) |
|
| 99 | - return urldecode($dat_ass[$key]); |
|
| 105 | + if(is_string($dat_ass[$key])) { |
|
| 106 | + return urldecode($dat_ass[$key]); |
|
| 107 | + } |
|
| 100 | 108 | |
| 101 | 109 | // $dat_ass[$key] is not a string, return match[$key] |
| 102 | 110 | return $dat_ass[$key]; |
@@ -146,7 +154,7 @@ discard block |
||
| 146 | 154 | { |
| 147 | 155 | try{ |
| 148 | 156 | $url = $this->generate($route, $route_params); |
| 149 | - }catch(\Exception $e){ |
|
| 157 | + } catch(\Exception $e){ |
|
| 150 | 158 | $url = $this->prehop(self::ROUTE_HOME_NAME); |
| 151 | 159 | } |
| 152 | 160 | |
@@ -169,12 +177,13 @@ discard block |
||
| 169 | 177 | { |
| 170 | 178 | $url = null; |
| 171 | 179 | |
| 172 | - if(is_null($route)) |
|
| 173 | - $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
| 174 | - elseif(is_string($route) && $this->route_exists($route)) |
|
| 175 | - $url = $this->prehop($route, $route_params); |
|
| 176 | - else |
|
| 177 | - $url = $route; |
|
| 180 | + if(is_null($route)) { |
|
| 181 | + $url = $this->prehop(self::ROUTE_HOME_NAME, $route_params); |
|
| 182 | + } elseif(is_string($route) && $this->route_exists($route)) { |
|
| 183 | + $url = $this->prehop($route, $route_params); |
|
| 184 | + } else { |
|
| 185 | + $url = $route; |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | 188 | $this->hop_url($url); |
| 180 | 189 | } |
@@ -182,8 +191,9 @@ discard block |
||
| 182 | 191 | // hops back to previous page (referer()), or home if no referer |
| 183 | 192 | public function hop_back() |
| 184 | 193 | { |
| 185 | - if(!is_null($back = $this->referer())) |
|
| 186 | - $this->hop_url($back); |
|
| 194 | + if(!is_null($back = $this->referer())) { |
|
| 195 | + $this->hop_url($back); |
|
| 196 | + } |
|
| 187 | 197 | |
| 188 | 198 | $this->hop(); |
| 189 | 199 | } |
@@ -200,16 +210,18 @@ discard block |
||
| 200 | 210 | // returns null if same as current URL (prevents endless redirection loop) |
| 201 | 211 | public function referer() |
| 202 | 212 | { |
| 203 | - if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) |
|
| 204 | - return $_SERVER['HTTP_REFERER']; |
|
| 213 | + if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != $this->web_host() .$_SERVER['REQUEST_URI']) { |
|
| 214 | + return $_SERVER['HTTP_REFERER']; |
|
| 215 | + } |
|
| 205 | 216 | |
| 206 | 217 | return null; |
| 207 | 218 | } |
| 208 | 219 | |
| 209 | 220 | public function send_file($file_path) |
| 210 | 221 | { |
| 211 | - if(!file_exists($file_path)) |
|
| 212 | - throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
| 222 | + if(!file_exists($file_path)) { |
|
| 223 | + throw new RouterException('SENDING_NON_EXISTING_FILE'); |
|
| 224 | + } |
|
| 213 | 225 | |
| 214 | 226 | $file_name = basename($file_path); |
| 215 | 227 | |