call notify on __set()

This commit is contained in:
Dominik Liebler
2011-08-27 10:54:30 +02:00
parent b025906281
commit d6328ab622

View File

@@ -25,6 +25,8 @@ class UserObserver implements \SplObserver
class User implements \SplSubject
{
protected $_data = array();
/**
* @var array
*/
@@ -68,4 +70,20 @@ class User implements \SplSubject
$observer->update($this);
}
}
/**
* Ideally one would better write setter/getter for all valid attributes and only call notify()
* on attributes that matter when changed
*
* @param $name
* @param $value
* @return void
*/
public function __set($name, $value)
{
$this->_data[$name] = $value;
// notify the observers, that user has been updated
$this->notify();
}
}