-
-
Save Drarok/3912712 to your computer and use it in GitHub Desktop.
ServiceLocator/EventManager Traits
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 Protec\Stdlib; | |
use \Zend\EventManager\EventManagerInterface; | |
use \Zend\ServiceManager\ServiceLocatorAwareInterface; | |
trait EventManagerAwareTrait | |
{ | |
protected $event_manager; | |
/** | |
* getEventManager | |
* | |
* @return EventManagerInterface | |
*/ | |
public function getEventManager() | |
{ | |
if (is_null($this->event_manager) | |
&& $this instanceof ServiceLocatorAwareInterface | |
&& ! is_null($this->getServiceLocator()) | |
&& $this->getServiceLocator()->has('EventManager') | |
) { | |
$this->setEventManager( | |
$this->getServiceLocator()->get('EventManager')); | |
} | |
return $this->event_manager; | |
} | |
/** | |
* setEventManager | |
* | |
* @param EventManagerInterface $eventManager | |
*/ | |
public function setEventManager(EventManagerInterface $eventManager) | |
{ | |
$this->event_manager = $eventManager; | |
$this->event_manager->addIdentifiers( | |
array( | |
get_called_class(), | |
__CLASS__ | |
) | |
); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment