Zend\Mvc\Service\ServiceListenerFactory::__invoke PHP Method

__invoke() public method

Tries to get a service named ServiceListenerInterface from the service locator, otherwise creates a ServiceListener instance, passing it the container instance and the default service configuration, which can be overridden by modules. It looks for the 'service_listener_options' key in the application config and tries to add service/plugin managers as configured. The value of 'service_listener_options' must be a list (array) which contains the following keys: - service_manager: the name of the service manage to create as string - config_key: the name of the configuration key to search for as string - interface: the name of the interface that modules can implement as string - method: the name of the method that modules have to implement as string
public __invoke ( Interop\Container\ContainerInterface $container, $requestedName, array $options = null ) : Zend\ModuleManager\Listener\ServiceListenerInterface
$container Interop\Container\ContainerInterface
$options array
return Zend\ModuleManager\Listener\ServiceListenerInterface
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $configuration = $container->get('ApplicationConfig');
        $serviceListener = $container->has('ServiceListenerInterface') ? $container->get('ServiceListenerInterface') : new ServiceListener($container);
        if (!$serviceListener instanceof ServiceListenerInterface) {
            throw new ServiceNotCreatedException('The service named ServiceListenerInterface must implement ' . ServiceListenerInterface::class);
        }
        $serviceListener->setDefaultServiceConfig($this->defaultServiceConfig);
        if (isset($configuration['service_listener_options'])) {
            $this->injectServiceListenerOptions($configuration['service_listener_options'], $serviceListener);
        }
        return $serviceListener;
    }