Created
April 10, 2012 12:15
-
-
Save basz/2350974 to your computer and use it in GitHub Desktop.
events - locator - lazy vs non lazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Could the event manager handle this better? I would want the lazy behavior without typing as much... | |
$events = StaticEventManager::getInstance(); | |
// obvious method (Application\Service\StoreService is instanciated even when the event has not been triggered) | |
$events->attach('Application\Controller\PaypalController', 'transaction.completed', array($locator->get('Application\Service\StoreService'), 'processTransaction'), 100); | |
// lazy method (Application\Service\StoreService is instanciated when the event has been triggered) | |
$events->attach('Application\Controller\PaypalController', 'transaction.completed', function($e) use ($locator) { | |
$service = $locator->get('Application\Service\StoreService'); | |
$service->processTransaction($e); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment