40,6 → 40,21 |
abstract class Base |
{ |
/** |
* Determines if a strict model is enforced. |
* |
* If <code>true</code>, all publicly accessible properties |
* must have a getter if readable, and a setter if writable. |
* Otherwise, accesses to non-existing public properties will be |
* forwarded to the correspnding underline property if no getter |
* or setter has been defined for it. The default is |
* <code>false</code> (non-strict) as that speeds up property |
* accesses and eases implementation considerably. |
* |
* @var bool |
*/ |
protected static $_strict = false; |
|
/** |
* Retrieves a property value. |
* |
* Automagically called when attempting to read data |
64,9 → 79,15 |
|
if (property_exists($this, "_$name")) |
{ |
throw new \InvalidArgumentException("Property '{$name}' has no getter"); |
$class = get_class($this); |
if ($class::$_strict) |
{ |
throw new \InvalidArgumentException("Strict model: Property '{$name}' has no getter"); |
} |
|
return $this->{"_$name"}; |
} |
|
throw new \InvalidArgumentException("No such property: '{$name}'"); |
} |
|
97,9 → 118,16 |
|
if (property_exists($this, "_$name")) |
{ |
throw new \InvalidArgumentException("Property '{$name}' has no setter"); |
$class = get_class($this); |
if ($class::$_strict) |
{ |
throw new \InvalidArgumentException("Strict model: Property '{$name}' has no setter"); |
} |
|
$this->{"_$name"} = $value; |
return $value; |
} |
|
throw new \InvalidArgumentException("No such property: '{$name}'"); |
} |
} |