logikostech / events
Events helper for phalcon php projects
v1.0.0
2017-04-08 19:40 UTC
Requires
- php: >=5.6
- ext-phalcon: >=2.0
Requires (Dev)
- phpunit/phpunit: ^4.0
- techpivot/phalcon-ci-installer: >=1.0
This package is auto-updated.
Last update: 2025-01-21 21:03:10 UTC
README
Logikos\Events\EventsAwareTrait
Useful trait when using Phalcon\Events\EventsAwareInterface. Key feature is the attachEventListener method in that if an EventsManager is not yet being used by the component it will add one and then attach the event. This way you don't have to setup your events manager when you setup the \Phalcon\Di services and each controller or library using the componenet can attach their own events as they see fit on a case by case basis.
Usage
Add to class
class foo implements \Phalcon\Events\EventsAwareInterface { use \Logikos\Events\EventsAwareTrait; }
Add event handelers with ease
To listen for all events pass null
$component->attachEventListener(null, function(\Phalcon\Events\Event $event, $component, $data=null) { switch ($event->getType()) { case 'beforeAction' : // ... break; case 'afterAction' : // ... break; } });
Listen for specific event
$component->attachEventListener('beforeAction', function(\Phalcon\Events\Event $event, $component, $data=null) { // ... });