PropertyObserver is a simple component which tracks changes in registered object's properties. It's usefull if i.e. we want to check if some property of some object has changed since it was last checked.
We highly recommend to use autoloader generated by composer.phar
Adding reflection into composer.json
{
...
"require": {
...
"fsi/property-observer": "0.9.*"
...
},
...
}
Let's assume we have some $object
and we want to check if value of its name
property has changed between point A
and point B in our code.
use FSi\Component\PropertyObserver\PropertyObserver
$object = new SomeObjectClass();
$object->setName('some name')
// point A
$observer = new PropertyObserver();
$observer->saveValue($object, 'name');
// a lot of complex code
// point B
if ($observer->hasValueChanged($object, 'name')) {
// do something
} else {
// do something else
}
The whole magic behind mapping propery names to getters/setters (if necessary) is done by symfony/property-access under the hood.