Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.15 KB

README.md

File metadata and controls

48 lines (34 loc) · 1.15 KB

FSi PropertyObserver Component

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.

Setup and autoloading

We highly recommend to use autoloader generated by composer.phar

Adding reflection into composer.json

{
    ... 
    "require": {
        ... 
        "fsi/property-observer": "0.9.*" 
        ...
    },
    ...
}

Usage

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.