I am not sure if the title is the best way to describe this question.
This book - http://apress.com/book/view/9781590599099 - illustrates the implementation of the Unit of Work template. It is a bit like this.
class UoW(){
private array $dirty;
private array $clean;
private array $new;
private array $delete;
public static function markClean(Entity_Class $Object){
}
public static function markDirty(Entity_Class $Object){
}
public static function markNew(Entity_Class $Object){
}
public static function markDelete(Entity_Class $Object){
}
public function commit(){
}
}
class MyMapper(){
public function setName($value){
$this->name = $value;
UoW::markDirty($this);
}
}
(Ignoring static call problems and dependencies for a moment)
The author notes that this implementation requires the encoder to insert the appropriate UoW marking methods and that this selective execution of the template can lead to errors. Now, taking on the pros and cons of specific accessories, you could automate the UoW call as follows:
public function __set($key,$value){
if(property_exists($this,$key)){
$this->$key = $value;
UoW::markDirty($this);
}
}
So, my question is: how would you like to guarantee that the corresponding UoW method was called when setting the properties of the domain object?