mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-03 05:27:29 +02:00
call notify on __set()
This commit is contained in:
@@ -25,6 +25,8 @@ class UserObserver implements \SplObserver
|
|||||||
|
|
||||||
class User implements \SplSubject
|
class User implements \SplSubject
|
||||||
{
|
{
|
||||||
|
protected $_data = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@@ -68,4 +70,20 @@ class User implements \SplSubject
|
|||||||
$observer->update($this);
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user