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;
    }