Download the PHP package eniams/spy without Composer
On this page you can find all versions of the php package eniams/spy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package spy
Short Description Handler to know if an object was modified
License MIT
Homepage https://github.com/ismail1432/spy
Informations about the package spy
Spy
Spy helps you to know if an object was modified and allow you to fire/listen an event when the given object is modified.
⚠️ This project is a work in progress. ⚠️
Installation
How it works ?
Behind the scene:
The initial object will be copied with a specific cloner then value of the initial (copied) object and the manipulated (current) object will be compared on demand to check if there is some modifications.
Suppose you want to spy a foo
object to know if it was modified :
-
Tag the class to spy with an interface that will correspond to the chosen cloner, there is 2 built-in cloners :
Eniams\Spy\Cloner\DeepCopyClonerInterface
that use the famous library DeepCopy
or
Eniams\Spy\Cloner\SpyClonerLoadPropertyObjectInterface
orEniams\Spy\Cloner\SpyClonerInterface
that allows you to clone more deeper the object/array stored in properties
You can create a custom Cloner to copy your object :
- Create the Cloner that should implements
Eniams\Spy\Cloner\ClonerInterface
. - Create an interface related to the created Cloner that should implements
Eniams\Spy\SpyInterface
.
If you're using Symfony thanks to the autoconfigure tags you don't have to follow the next step, the created cloner will be
registered to the ChainCloner
that is responsible to clone the oject to spy.
So you can go to step 3.
-
For Vanilla PHP if you don't want to use the default cloners you can Register yours in the
Eniams\Spy\ClonerChainCloner
- Time to spy your object :shipit:
Now, you want to want to know if a specific property was modified and get the initial and the current value.
Working with Services container you can store an object in the SpyBase
to retrieve it later in your application
Symfony
Vanilla PHP
For simple use case that don't need to clone an object, you can also check the difference between 2 "same" classes.
More advanced use case
You can define a context to check some properties.
You can define dynamically which properties to check
You can exclude some properties.
All versions of spy with dependencies
myclabs/deep-copy Version 1.9.1
symfony/config Version ^4.3|^5.0
symfony/http-kernel Version ^4.3|^5.0
symfony/proxy-manager-bridge Version ^3.4|^4.4|^5.0