Download the PHP package leedavis81/vent without Composer
On this page you can find all versions of the php package leedavis81/vent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leedavis81/vent
More information about leedavis81/vent
Files in leedavis81/vent
Informations about the package vent
vent
PHP variable event system
Quality / Metrics | Releases | Downloads | Licence |
---|---|---|---|
![]() ![]() |
![]() ![]() |
![]() |
![]() |
Installation
Install via composer:
Usage
Have you ever needed to hook an event anytime a PHP variable is read? Maybe you want to ensure complete immutability even within the scope (private) of your class. PHP variable events can be easily created by hooking into the read or write of any variable.
Or you can register a write event to protect the variable from being overwritten (even from within the scope of your class)
You can masquerade any value by returning something from your registered event. Note that if multiple events are registered, execution they will stop once one of them returns a response. They are triggered in the order they're registered (first in, first out).
To pass in parameters into your method simply provide them when registering the event.
Please note there are two reserved strings that if passed in as a parameter will be replaced
_OVL_NAME_
replaced with the name of the variable you're accessing (set or get)_OVL_VALUE_
replaced with the value your updating a variable with (set only)_CUR_VALUE_
the current value of the variable
If you are returning a response on your event, this can be retained to prevent additional execution on further reads. If you don't return anything from your action (or return a null) then nothing is retained and additional reads will cause re-execution of your registered action.
All events must be registered within the context of your class when using VentTrait
. However, if you'd like to register them from a public or protected scope then simply change the scope of the registerEvent
method when importing the trait
Supported Events
Event Name | Alias | Triggered |
---|---|---|
read | get | Whenever an attempt to read the variable is performed |
write | set | Whenever an attempt to write to the variable is performed |
delete | unset | Whenever unset is called on the variable. Setting to null will not work. |
But you stole my magic
It's true that this little trait applies a __get
and __set
method to your class. If your class already has a little magic and these methods have already been applied then they'll overwrite the trait implementation. Maybe not what you want. To get around this you can simply import them with a different method name, and call them in your own magic methods. For example:
todos
- Allow event triggering for array offset reads $foo->bar['offset'];
- Add a method to remove variables from proxy (to increase perf)