Skip to content

Instantly share code, notes, and snippets.

@comfuture
Created May 11, 2011 08:06
Show Gist options
  • Save comfuture/966090 to your computer and use it in GitHub Desktop.
Save comfuture/966090 to your computer and use it in GitHub Desktop.
<?php
namespace webapp;
/**
* base Doctrine entity for convinent orm association
*/
class BaseEntity
{
protected $_properties;
function __construct($initValues=null)
{
if (is_array($initValues)) {
foreach ($initValues as $name=>$value) {
$this->{$name} = $value;
}
}
}
protected function properties()
{
if (null === $this->_properties)
$this->_properties = array_keys(get_class_vars(get_class($this)));
return $this->_properties;
}
public function __isset($key)
{
return in_array($key, $this->properties());
}
public function __get($key)
{
if (in_array($key, $this->properties()))
return $this->{$key};
return null;
}
public function __set($key, $value)
{
if (in_array($key, $this->properties())) {
$this->{$key} = $value;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment