Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 71 → Rev 72

/trunk/StrictModel.php
0,0 → 1,13
<?php
 
namespace PointedEars\PHPX;
 
/**
* Abstract model class for strict Object-Relational Mapping
*
* @author Thomas Lahn
*/
abstract class StrictModel extends \PointedEars\PHPX\Model
{
protected static $_strict = true;
}
/trunk/Base.php
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
63,8 → 78,14
}
 
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}'");
94,10 → 115,17
{
return $this->$setter($value);
}
 
 
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}'");