From 1c6c4be0c8a71c32fa6047d6a56aae2a8635db2b Mon Sep 17 00:00:00 2001 From: filbar Date: Sun, 27 Jul 2014 15:23:39 +0200 Subject: [PATCH] Adding possibility to use php magic methods __get for retrieving attributes --- src/Engine.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Engine.php b/src/Engine.php index a257fdf..9267899 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -289,17 +289,21 @@ public function getAttribute($object, $name, array $args = array(), $type = self self::$classes[$class] = array_change_key_case(array_flip(get_class_methods($object))); } - if (!isset(self::$classes[$class][$item])) { - if (isset(self::$classes[$class]["get$item"])) { - $name = "get$name"; - } elseif (isset(self::$classes[$class]["is$item"])) { - $name = "is$name"; - } elseif (isset(self::$classes[$class]["__call"])) { - $call = true; - } else { - return null; - } - } + if (isset(self::$classes[$class]['__get'])) { + return $object->$name; + } else { + if (!isset(self::$classes[$class][$item])) { + if (isset(self::$classes[$class]["get$item"])) { + $name = "get$name"; + } elseif (isset(self::$classes[$class]["is$item"])) { + $name = "is$name"; + } elseif (isset(self::$classes[$class]["__call"])) { + $call = true; + } else { + return null; + } + } + } try { return call_user_func_array(array($object, $name), $args);