This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GenericEntity extends Data | |
| { | |
| use MagicArrayAccessTrait; | |
| public function offsetGet($key) | |
| { | |
| return $this->$key; | |
| } | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * Calls ArrayAccess::offsetGet() to get a field value; converts Lazy | |
| * objects for related entities and collections in place. | |
| * | |
| * @param string $field The field name to get. | |
| * | |
| * @return mixed The field value. | |
| * | |
| */ | |
| public function __get($field) | |
| { | |
| // get the field value | |
| $value = $this->data[$field]; | |
| // is it a Lazy placeholder? | |
| if ($value instanceof LazyInterface) { | |
| // replace the Lazy placeholder with the real object | |
| $value = $value->get($this); | |
| } | |
| // done! | |
| return $value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment