Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 58 → Rev 59

/trunk/AbstractModel.php
17,12 → 17,11
/**
* Abstract model class
*
* Provides basic setters and getters for protected/private properties
* and a constructor to initialize properties using setters and getters.
* Provides a constructor to initialize properties using setters and getters.
*
* @author Thomas Lahn
*/
abstract class AbstractModel
abstract class AbstractModel extends Base
{
/**
* Creates a new model object
39,62 → 38,6
}
 
/**
* Getter for properties
*
* @param string $name
* @throws ModelPropertyException
* @return mixed
*/
public function __get ($name)
{
/* Support for Object-Relational Mappers */
// if (strpos($name, 'persistent') === 0)
// {
// $class = get_class($this);
// return $class::${"_" . $name};
// }
 
$method = 'get' . ucfirst($name);
 
if (method_exists($this, $method))
{
return $this->$method();
}
 
if (property_exists($this, "_$name"))
{
return $this->{"_$name"};
}
 
return $this->$name;
}
 
/**
* Setter for properties
*
* @param string $name
* @param mixed $value The new property value before assignment
* @throws ModelPropertyException
*/
public function __set ($name, $value)
{
$method = 'set' . ucfirst($name);
 
if (method_exists($this, $method))
{
return $this->$method($value);
}
 
if (property_exists($this, "_$name"))
{
$this->{"_$name"} = $value;
return $this->{"_$name"};
}
 
/* NOTE: Attempts to set other properties are _silently_ _ignored_ */
}
 
/**
* Returns <code>true</code> if a variable name is a property variable name
* (starts with <tt>$_</tt>), <code>false</code> otherwise.
*