From 737401a1e99a89c2bffe749e27bb01ddef0730c9 Mon Sep 17 00:00:00 2001 From: Ti-Tom Date: Mon, 5 Feb 2024 14:46:45 +0100 Subject: [PATCH] DEV: FieldsTrait > remove dynamic properties in __set method & return $this --- Pragma/Forms/Fields/FieldsTrait.php | 47 ++++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Pragma/Forms/Fields/FieldsTrait.php b/Pragma/Forms/Fields/FieldsTrait.php index 687b023..c271b8c 100644 --- a/Pragma/Forms/Fields/FieldsTrait.php +++ b/Pragma/Forms/Fields/FieldsTrait.php @@ -1,60 +1,65 @@ params); - if(!empty($extra_params)){ - foreach($extra_params as $k){ + if (!empty($extra_params)) { + foreach ($extra_params as $k) { unset($params[$k]); } } - if(!empty($params)){ + if (!empty($params)) { $this->params = array_merge($this->params, $params); - if(is_null($this->id) || empty($this->id) && !empty($this->name)){ + if (is_null($this->id) || empty($this->id) && !empty($this->name)) { $this->id = $this->name; } } } - public function __set($key, $value){ - if(array_key_exists($key, $this->params)){ + public function __set($key, $value) + { + if (array_key_exists($key, $this->params)) { $this->params[$key] = $value; } - else{ - $this->$key = $value; - } + return $this; } - public function __get($key){ - if(array_key_exists($key, $this->params)){ + public function __get($key) + { + if (array_key_exists($key, $this->params)) { return $this->params[$key]; - } - else{ + } else { return null; } } - public function __isset($key){ + public function __isset($key) + { return array_key_exists($key, $this->params) && isset($this->params[$key]); } - public static function getField($params = []){ - $class= get_called_class(); + public static function getField($params = []) + { + $class = get_called_class(); return new $class($params); } - public function setForm($form){ + public function setForm($form) + { $this->form = $form; return $this; } - public function getType(){ + public function getType() + { return $this->type; } }