Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MutableDomainObject extends ImmutableDomainObject implements IObservable
- {
- protected $modified = false;
- protected $observable;
- protected function __construct()
- {
- $this->observable = new Observable();
- $this->observable->registerEvents(array('invalidate','modified'));
- }
- function __call($method, array $args)
- {
- if ( substr($method,0,3) == 'set' )
- {
- $propname = substr($method, 3);
- if ( sizeof($args) <= 0 )
- {
- throw new DomainObjectException
- ("Mutator $method requires an argument");
- }
- $validator = "validate$propname";
- if ( method_exists($this, $validator) )
- {
- if ( !$this->$validator($args[0]) )
- {
- $this->observable->fireEvent('invalidate',
- $propname, $args[0], $this);
- return false;
- }
- }
- $this->$propname = $args[0];
- $this->observable->fireEvent('modified',$propname,$args[0],$this);
- return $this->modified = true;
- }
- return parent::__call($method, $args);
- }
- function on($eventId,$callback,$context=null,$addArg=null)
- {
- $this->observable->on($eventId,$callback,$context,$addArg);
- }
- function un($eventId,$callback,$context=null,$addArg=null)
- {
- $this->observable->un($eventId,$callback,$context,$addArg);
- }
- function isModified()
- {
- return $this->modified;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment