davedevelopment / pimple-aware-event-dispatcher
A Symfony compatible event dispatcher that allows services to be lazy loaded from an instance of the Pimple DI container
Installs: 2 533
Dependents: 1
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- pimple/pimple: 3.*
- symfony/event-dispatcher: ~2.1
Requires (Dev)
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2024-11-17 08:38:15 UTC
README
Installation
composer.phar require "davedevelopment/pimple-aware-event-dispatcher:*@dev"
Usage
To use in a Silex application:
<?php use PimpleAwareEventDispatcher\PimpleAwareEventDispatcher; use Silex\Application; use Symfony\Component\EventDispatcher\EventDispatcher; $app = new Application; // define the dispatcher $app['event_dispatcher'] = function () use ($app) { $dispatcher = new EventDispatcher(); return new PimpleAwareEventDispatcher($dispatcher, $app); }; // define our application services $app['some.service'] = function() use ($app) { // let's assume this takes a bit of doing and/or is dependant on several other // services sleep(1); return new SomeService; }; // add a listener, that will lazily fetch the service when needed $app['event_dispatcher']->addListenerService( "some.event", array("some.service", "serviceMethod") );