Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions Pragma/Forms/Fields/FieldsTrait.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
<?php
namespace Pragma\Forms\Fields;

trait FieldsTrait{
namespace Pragma\Forms\Fields;

trait FieldsTrait
{
protected $form = null;

public function __construct($params = []){
public function __construct($params = [])
{
//ensure that the user does'nt add extra params
$extra_params = array_diff_key($params, $this->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;
}
}