Skip to content

Commit

Permalink
correcao
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Morais authored and Bruno Morais committed Dec 16, 2023
1 parent 2103d0a commit 92ecd09
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/ModelAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

abstract class ModelAbstract
{
protected array $dataArray = [];

/**
* @param array|null $params
*/
Expand All @@ -35,6 +37,7 @@ public function fromMapToModel(array $params): void
{
foreach ($params as $key => $item) {
$this->{$key} = $item;
$this->dataArray[$key] = $item;
}
}

Expand All @@ -49,8 +52,8 @@ public function fromJsonToModel(string $json): void
}

/**
* @param $objArray
* @return array|null
* @param $objArray
* @return array|null
*/
public function toMap($objArray = null): ?array
{
Expand Down Expand Up @@ -88,31 +91,38 @@ public function toString(): string
}

return $classname . ' {' . implode(', ', array_map(
function ($p_0) use ($data) {
$p_0->setAccessible(true);
function ($p_0) use ($data) {
$p_0->setAccessible(true);

return $p_0->getName() . ': ' . $p_0->getValue($data);
},
$re_2->getProperties()
)) . '}';
return $p_0->getName() . ': ' . $p_0->getValue($data);
},
$re_2->getProperties()
)) . '}';
}

/**
* @param $attribute
* @return string
*/
public function __get($attribute): string
/**
* @param $name
* @return string
*/
public function __get($name): string
{
return $this->{$attribute} ?? '';
return $this->{$name} ?? ($this->dataArray[$name]?? "");
}

/**
* @param $attribute
* @param $name
* @param $value
* @return void
*/
public function __set($attribute, $value): void
public function __set($name, $value): void
{
$this->{$attribute} = $value;
$this->{$name} = $value;
$this->dataArray[$name] = $value;
}

}

0 comments on commit 92ecd09

Please sign in to comment.