Skip to content

Commit

Permalink
Optimized the model fields setters and getters.
Browse files Browse the repository at this point in the history
  • Loading branch information
phrenotype committed Jun 29, 2024
1 parent d2220d5 commit 5ecff0e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Q/Orm/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ public function __construct($fields = [])
public function __call($name, $args)
{
$value = method_exists($this, $name);
if($value){
if ($value) {
$value = $this->$value;
}else{
} else {
$value = $this->__properties[$name];
}

if ($value) {

if ($value instanceof \Closure) {

//Reset prevState, since we just opened up a closure
//Get prevState for restoring later, since we just opened up a closure
$prevState = $this->prevState();
foreach ($prevState as $k => $v) {
if ($k === $name) {
$prevState[$k] = $value;
}
}
$this->prevState($prevState);

return ($value)();
}
return $value;
Expand All @@ -58,22 +58,23 @@ public function __call($name, $args)
public function __get($name)
{
$inProps = $this->__properties[$name] ?? null;
if($inProps){
if($inProps instanceof \Closure){
if ($inProps) {
if ($inProps instanceof \Closure) {
$evaluated = $this->$name();
return $this->$name();
}else{
return $evaluated;
} else {
return $inProps;
}
}
}
}

public function __set($name, $value)
{
$this->__properties[$name] = $value;
}

public function getProps(){
public function getProps()
{
return $this->__properties;
}

Expand Down

0 comments on commit 5ecff0e

Please sign in to comment.