Skip to content

Commit

Permalink
adicionar o toObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Morais authored and Bruno Morais committed Oct 20, 2024
1 parent ff7bb81 commit 23065b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,4 @@ public function getLogSQL(): ?string
return $this->logSQL ?? "";
}

public function extractModel($model): \stdClass{
$reflection = new \ReflectionClass(get_class($model));
$objeto = new \stdClass;

foreach ($reflection->getProperties() as $prop) {
$method = 'get'.$prop->name ;
$objeto->{$prop->name} = call_user_func([$model, $method]);

}

return $objeto ;


}

}
19 changes: 19 additions & 0 deletions src/ModelAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ public function toMap($objArray = null): ?array
return null;
}

public function toObject(): \stdClass{
$reflection = new \ReflectionClass($this);
$objeto = new \stdClass;

foreach ($reflection->getProperties() as $prop) {
$prop->setAccessible(true);

$method = 'get' . $prop->getName();

if (method_exists($this, $method)) {
$objeto->{$prop->getName()} = call_user_func([$this, $method]);
} else {
$objeto->{$prop->getName()} = $prop->getValue($this);
}
}

return $objeto;
}

/**
* @return string
*/
Expand Down

0 comments on commit 23065b4

Please sign in to comment.