Skip to content

PropertyObserver is a simple component which tracks changes in registered object's properties.

License

Notifications You must be signed in to change notification settings

chives/property-observer

 
 

Repository files navigation

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.

About

PropertyObserver is a simple component which tracks changes in registered object's properties.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%