* @copyright 2009, Juraj Seffer * @version $Id$ * @access public */ abstract class MagicMethods_Abstract { /** * Magic getter * * @param string $property * @access protected * @return mixed */ protected function __get($property) { $getterMethod = "get" . strtoupper($property); if (method_exists($this, $getterMethod)) { return $this->$getterMethod(); } else if (!property_exists($this, $property)) { throw new MagicMethodsException("Cannot get property '$property'. Not defined in class " . get_class($this)); } else { return $this->$property; } } /** * Magic setter * * @param string $property * @param mixed $value * @access protected * @return void */ protected function __set($property, $value) { $setterMethod = "set" . strtoupper($property); if (method_exists($this, $setterMethod)) { return $this->$setterMethod($value); } else if (!property_exists($this, $property)) { throw new MagicMethodsException("Cannot set property '$property'. Not defined in class " . get_class($this)); } else { $this->$property = $value; } } /** * Magic isset * * @param string $property * @access protected * @return mixed */ protected function __isset($property) { if (!property_exists($this, $property)) { throw new MagicMethodsException("Property '$property' not defined in class " . get_class($this)); } else { return isset($this->$property); } } /** * Magic unset * * @param string $property * @access protected * @return void */ protected function __unset($property) { if (!property_exists($this, $property)) { throw new MagicMethodsException("Property '$property' not defined in class " . get_class($this)); } else { $this->$property = null; } } }