Skip to content

Instantly share code, notes, and snippets.

@jakefolio
Created January 29, 2014 17:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jakefolio/8e8cc4a64df54021655e to your computer and use it in GitHub Desktop.
class GenericEntity extends Data
{
use MagicArrayAccessTrait;
public function offsetGet($key)
{
return $this->$key;
}
}
/**
*
* 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