Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Application\Entity;
- abstract class AbstractEntity
- {
- /**
- * inputFilter
- *
- * @var InputFilter
- * @access protected
- */
- protected $inputFilter;
- /**
- * __construct function.
- *
- * @access public
- * @param array $options (default: array())
- * @return void
- */
- public function __construct($options = array())
- {
- $this->setOptions($options);
- }
- /** TEMP **/
- /**
- * __call function.
- *
- * @access public
- * @param mixed $method
- * @param mixed $args
- * @return void
- */
- public function __call($method, $args)
- {
- if (strpos($method, 'get') !== false) {
- $property = strtolower(str_replace('get', '', $method));
- if (property_exists($this, $property)) {
- return $this->{$property};
- } else {
- throw new \Exception('Property not valid.');
- }
- }
- }
- /**
- * set function.
- *
- * @access public
- * @param string $key
- * @param mixed $value
- * @return void
- */
- public function set($key, $value)
- {
- if (property_exists($this, $key)) {
- $this->{$key} = $val;
- }
- }
- /** /TEMP **/
- /**
- * __get function.
- *
- * @access public
- * @param mixed $propertyName
- * @return void
- */
- public function __get($propertyName)
- {
- $methodName = 'get' . ucfirst($propertyName);
- if (method_exists($this, $methodName)) {
- return $this->$methodName();
- } else {
- throw new \Exception('Attempting to get an invalid property.');
- }
- }
- /**
- * __set function.
- *
- * @access public
- * @param string $propertyName
- * @param mixed $propertyValue
- * @return AbstractEntity
- */
- public function __set($propertyName, $propertyValue)
- {
- $methodName = 'set' . ucfirst($propertyName);
- if (method_exists($this, $methodName)) {
- $this->$methodName($propertyValue);
- return $this;
- } else {
- throw new \Exception('Attempting to set an invalid property.');
- }
- }
- /**
- * setOptions function.
- *
- * @access public
- * @param array $options (default: array())
- * @return AbstractEntity
- */
- public function setOptions($options = array())
- {
- foreach ($options as $propertyName => $propertyValue) {
- $methodName = 'set' . ucfirst($propertyName);
- if (method_exists($this, $methodName)) {
- $this->$methodName($propertyValue);
- }
- }
- return $this;
- }
- /**
- * getArrayCopy function.
- *
- * @access public
- * @return array
- */
- public function getArrayCopy()
- {
- return get_object_vars($this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement