code: protected function createEventManager($services, $config)
      {
          /* @var \Zend\EventManager\EventManagerInterface|\Core\EventManager\EventProviderInterface $events */
  
          if ($services->has($config['service'])) {
              $events = $services->get($config['service']);
          } else {
              if (!class_exists($config['service'], true)) {
                  throw new \UnexpectedValueException(sprintf(
                      'Class or service %s does not exists. Cannot create event manager instance.',
                      $config['service']
                  ));
              }
  
              $events = new $config['service']();
          }
  
          if (false === $config['configure']) {
              return $events;
          }
  
          $events->setIdentifiers($config['identifiers']);
      
          /* @var \Zend\EventManager\EventInterface $event */
          $event = $services->has($config['event']) ? $services->get($config['event']) : new $config['event']();
          $events->setEventPrototype($event);
  
          if ('EventManager' != $config['service'] && method_exists($events, 'setSharedManager') && $services->has('SharedEventManager')) {
              /* @var \Zend\EventManager\SharedEventManagerInterface $sharedEvents */
              $sharedEvents = $services->get('SharedEventManager');
              $events->setSharedManager($sharedEvents);
          }
  
          return $events;
      }
docs: Creates an event manager instance.
  
  Fetches from the service manager or tries to instantiate direct, if no service
  exists in the service manager.
  
  If the key 'configure' in the config array has the value TRUE (default),
  the event manager instance will get configured. Which means, the event prototype
  will be set (after it is fetched from the service manager or instatiated),
  and the shared event manager will be injected.
  
  @param ServiceLocatorInterface $services
  @param array $config
  
  @return \Zend\EventManager\EventManagerInterface
  @throws \UnexpectedValueException if neither a service exists, nor could a class be found.