Created
March 9, 2012 21:51
-
-
Save weierophinney/2008921 to your computer and use it in GitHub Desktop.
EventManager injection
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
<?php | |
namespace Zend\EventManager; | |
/** | |
* EventManager can compose static connections. | |
* | |
* What I'd like to see: classes that accept an EM always get a new instance, | |
* but each EM instance each receives the *same* instance of a | |
* StaticEventCollection. | |
* | |
*/ | |
class EventManager | |
{ | |
protected $staticConnections; | |
/** | |
* @var EventManager | |
*/ | |
public function setStaticConnections(StaticEventCollection $collection) | |
{ | |
$this->staticConnections = $collection; | |
} | |
} |
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
<?php | |
namespace Foo\Controller | |
use Zend\Mvc\Controller\ActionController, | |
Zend\EventManager\EventCollection, | |
Zend\EventManager\EventManager; | |
/** | |
* controllers compose an EventManager instance | |
*/ | |
class FooController | |
{ | |
/** | |
* @var EventManager | |
*/ | |
protected $events; | |
public function setEventManager(EventCollection $events) | |
{ | |
$events->setIdentifier(array( | |
'Zend\Stdlib\Dispatchable', __CLASS__, get_called_class(), | |
)); | |
$this->events = $events; | |
} | |
public function events() | |
{ | |
if (!$this->events instanceof EventCollection) { | |
$this->setEventManager(new EventManager()); | |
} | |
return $this->events; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment