Download the PHP package phossa2/event without Composer
On this page you can find all versions of the php package phossa2/event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phossa2/event
More information about phossa2/event
Files in phossa2/event
Package event
Short Description PSR-14 event manager implementation libraray for PHP
License MIT
Homepage https://github.com/phossa2/event
Informations about the package event
phossa2/event [ABANDONED]
PLEASE USE phoole/event library instead
phossa2/event is a PSR-14 event manager library for PHP.
It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with PSR-1, PSR-2, PSR-4 and the upcoming PSR-14
Installation
Install via the composer
utility.
or add the following lines to your composer.json
Features
-
Event name globbing.
-
Built-in multiple shared event managers support.
-
Attach and detach listeners.
-
Static event manager support.
-
Built-in class level events support.
- Able to limit number of times of an event callable executed.
Usage
-
Event name globbing means callables of the binding 'login.*' will also be triggered when triggering event 'login.success'.
The globbing rules are similiar to the PHP function
glob()
, where-
*
in the string means any chars except the dot. -
If
*
at the end, will match any chars including the dot. e.g.login.*
will match 'login.attempt.before'. -
.
means the dot. - one-char-string
*
means match any string (including the dot).
Note: Name globbing ONLY happens when event is being triggered. Binding or unbinding events only affect the EXACT event name.
-
-
Class
EventDispatcher
implements thePhossa2\Shared\Shareable\ShareableInterface
.ShareableInterface
is an extended version of singleton pattern. Instead of supporting only one shared instance, Classes implementsShareableInterface
may have shared instance for differentscope
.Callables bound to a shared manager will also be triggered if an event manager instance has the same scope.
Event manager instance can have multiple scopes, either specified during the instantiation or using
addScope()
.Couple of helper methods are provided for on/off/trigger events with shared managers.
-
Listener
implements theListenerInterface
. Or in short, provides a methodeventsListening()
.EventDispatcher::attachListener()
can be used to bind events defined ineventsListening()
instead of usingEventDispatcher::attach()
to bind each event manually. -
Using event manager statically
StaticEventDispatcher
is a static wrapper for anEventDispatcher
slave.StaticEventDispatcher
is not the same as global event manager.StaticEventDispatcher
has a default slave which is a shared event manager in scope'__STATIC__'
. While global event manager is the shared event manager in global scope''
.User may set another event manager to replace the default slave.
-
EventCapableAbstract
EventCapableAbstract
implements bothListenerInterface
andEventCapableInterface
. It will do the following whentriggerEvent()
is called,-
Get the event manager. If it is not set yet, create one default event manager with current classname as scope.
-
Attach events defined in
eventsListening()
if not yet. - Trigger the event and processed by the event manager and all of the shared managers of its scopes.
-
-
EventableExtensionAbstract
andEventableExtensionCapableAbstract
EventableExtensionCapableAbstract
is the base class supporting events and extensions.Detail usage can be found in phossa2/cache
Phossa2\Cache\CachePool
extendsEventableExtensionCapableAbstract
andPhossa2\Cache\Extension\ByPass
extendsEventableExtensionAbstract
.Or look at phossa2/route.
-
Class or interface level events support
Class or interface name can be used as the
scope
. When events bound to these kind of scopes, any events triggered by child class will also search callables defined in parent class/interface level shared event managers.Extends
EventCapableAbstract
. - Execute callable for limited times
Change log
Please see CHANGELOG from more information.
Testing
Contributing
Please see CONTRIBUTE for more information.
Dependencies
-
PHP >= 5.4.0
- phossa2/shared >= 2.0.21