/**
  * Initialize
  *
  * @param $instance
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function initialize($instance, ServiceLocatorInterface $serviceLocator)
 {
     if (!$instance instanceof EventsCapableInterface) {
         return;
     }
     if ($serviceLocator instanceof AbstractPluginManager) {
         $serviceLocator = $serviceLocator->getServiceLocator();
     }
     $events = $instance->getEventManager();
     if ($serviceLocator->has('config')) {
         $config = $serviceLocator->get('config');
     } else {
         $config = array();
     }
     if (isset($config['abacaphiliac/events-capable'])) {
         $options = new EventsCapableOptions($config['abacaphiliac/events-capable']);
     } else {
         $options = new EventsCapableOptions(array());
     }
     $listeners = $options->getListeners($instance);
     foreach ($listeners as $listener) {
         if (is_string($listener)) {
             $listener = $this->getListener($serviceLocator, $listener);
         }
         if ($listener instanceof ListenerAggregateInterface) {
             $listener->attach($events);
         }
         // TODO Get listener spec from config (e.g. event-name, callable, and priority.
     }
 }
 public function testGetListeners()
 {
     $eventsCapable = $this->getMock('\\Zend\\EventManager\\EventsCapableInterface');
     $this->sut->setFromArray(array('eventsCapable' => array(get_class($eventsCapable) => array($listenerName = 'MyListener'))));
     $actual = $this->sut->getListeners($eventsCapable);
     $this->assertContains($listenerName, $actual);
 }