Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Adding possibility to use php magic methods __get for retrieving attribu... #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down