Created
May 11, 2011 08:06
-
-
Save comfuture/966090 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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