From ba8f3b8014c25947d77179013fa99a9f8e2cbec7 Mon Sep 17 00:00:00 2001 From: therselman Date: Sat, 26 Aug 2017 13:16:37 +0200 Subject: [PATCH] --- src/ORM/Entity.php | 47 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/ORM/Entity.php b/src/ORM/Entity.php index ab66bd3..f08dd5b 100644 --- a/src/ORM/Entity.php +++ b/src/ORM/Entity.php @@ -1,22 +1,16 @@ properties =& $properties; + $this->id = $properties['id'] ?? null; } /** @@ -25,10 +19,12 @@ class Entity * @param string $name * @return mixed */ - public function __get($name) + function __get($name) { - $value = $this->properties[$name]; - return is_callable($value) ? $value($this) : $value; + if ( ! isset($this->properties[$name])) + $this->load($name); + + return $this->properties[$name]; } /** @@ -38,34 +34,19 @@ class Entity * @param mixed $value * @return void */ - public function __set($name, $value) + function __set($name, $value) { $this->properties[$name] = $value; } - - public function __isset($name) + function __isset($name) { return isset($this->properties[$name]); } - public function __unset($name) + function __unset($name) { unset($this->properties[$name]); } - - public function __call($method, ...$args) - { - array_unshift($args, $this); - return call_user_func($this->properties[$method], ...$args); - } - public function __invoke() - { - return $this->properties['__invoke']($this); - } - public function setMethod($method, callable $callable) - { - $this->properties[$method] = $callable; - return $this; - } + abstract function load(...$args); }