/**
  * Constructor
  *
  * Merges internal arrays with those passed via configuration, and also
  * defines:
  *
  * - factory for the service 'SharedEventManager'.
  * - initializer for EventManagerAwareInterface implementations
  *
  * @param  array $config
  */
 public function __construct(array $config = [])
 {
     $this->config['factories']['ServiceManager'] = function ($container) {
         return $container;
     };
     $this->config['factories']['SharedEventManager'] = function () {
         return new SharedEventManager();
     };
     $this->config['initializers'] = ArrayUtils::merge($this->config['initializers'], ['EventManagerAwareInitializer' => function ($first, $second) {
         if ($first instanceof ContainerInterface) {
             $container = $first;
             $instance = $second;
         } else {
             $container = $second;
             $instance = $first;
         }
         if (!$instance instanceof EventManagerAwareInterface) {
             return;
         }
         $eventManager = $instance->getEventManager();
         // If the instance has an EM WITH an SEM composed, do nothing.
         if ($eventManager instanceof EventManagerInterface && $eventManager->getSharedManager() instanceof SharedEventManagerInterface) {
             return;
         }
         $instance->setEventManager($container->get('EventManager'));
     }]);
     // In zend-servicemanager v2, incoming configuration is not merged
     // with existing; it replaces. So we need to detect that and merge.
     if (method_exists($this, 'getAllowOverride')) {
         $config = ArrayUtils::merge($this->config, $config);
     }
     parent::__construct($config);
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * Merges internal arrays with those passed via configuration
  *
  * @param  array $configuration
  */
 public function __construct(array $configuration = array())
 {
     $this->initializers = array('EventManagerAwareInitializer' => function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof EventManagerAwareInterface) {
             $eventManager = $instance->getEventManager();
             if ($eventManager instanceof EventManagerInterface) {
                 $eventManager->setSharedManager($serviceLocator->get('SharedEventManager'));
             } else {
                 $instance->setEventManager($serviceLocator->get('EventManager'));
             }
         }
     }, 'ServiceManagerAwareInitializer' => function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($serviceLocator instanceof ServiceManager && $instance instanceof ServiceManagerAwareInterface) {
             $instance->setServiceManager($serviceLocator);
         }
     }, 'ServiceLocatorAwareInitializer' => function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($serviceLocator);
         }
     });
     $this->factories['ServiceManager'] = function (ServiceLocatorInterface $serviceLocator) {
         return $serviceLocator;
     };
     parent::__construct(ArrayUtils::merge(array('invokables' => $this->invokables, 'factories' => $this->factories, 'abstract_factories' => $this->abstractFactories, 'aliases' => $this->aliases, 'shared' => $this->shared, 'delegators' => $this->delegators, 'initializers' => $this->initializers), $configuration));
 }
 public function __construct()
 {
     parent::__construct($this->configServiceManager());
 }