Exemplo n.º 1
0
 public function setupServiceManager()
 {
     $options = array('service_manager' => array('factories' => array('ViewHelperManager' => 'Zend\\Mvc\\Service\\ViewHelperManagerFactory', 'ControllerPluginManager' => 'Zend\\Mvc\\Service\\ControllerPluginManagerFactory')));
     $config = ArrayUtils::merge($options['service_manager'], $this->module->getServiceConfig());
     $config['view_helpers'] = $this->module->getViewHelperConfig();
     $config['controller_plugins'] = $this->module->getControllerPluginConfig();
     $services = new ServiceManager();
     $servicesConfig = new Config($config);
     $servicesConfig->configureServiceManager($services);
     $services->setService('Config', $config);
     $event = new MvcEvent();
     $event->setRouteMatch(new RouteMatch(array()));
     $router = $this->getMock('Zend\\Mvc\\Router\\RouteStackInterface');
     $services->setService('HttpRouter', $router);
     $app = $this->getMockBuilder('Zend\\Mvc\\Application')->disableOriginalConstructor()->getMock();
     $app->expects($this->once())->method('getMvcEvent')->will($this->returnValue($event));
     $services->setService('application', $app);
     $helpers = $services->get('ViewHelperManager');
     $helpersConfig = new Config($config['view_helpers']);
     $helpersConfig->configureServiceManager($helpers);
     $plugins = $services->get('ControllerPluginManager');
     $pluginsConfig = new Config($config['controller_plugins']);
     $pluginsConfig->configureServiceManager($plugins);
     return $services;
 }
 /**
  * Set up service manager and database configuration.
  *
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 protected function setUp()
 {
     $serviceManagerConfig = new Config(['factories' => ['SphinxSearch\\Db\\Adapter\\Adapter' => 'SphinxSearch\\Db\\Adapter\\AdapterServiceFactory'], 'alias' => ['sphinxql' => 'SphinxSearch\\Db\\Adapter\\Adapter']]);
     $this->serviceManager = new ServiceManager();
     $serviceManagerConfig->configureServiceManager($this->serviceManager);
     $this->serviceManager->setService('Config', ['sphinxql' => ['driver' => 'pdo_mysql']]);
 }
 public function testCannotCreateServiceWithMissingDependency()
 {
     $config = new Config(['factories' => [BarService::class => ReflectionFactory::class, QuxService::class => ReflectionFactory::class]]);
     $container = new ServiceManager();
     $config->configureServiceManager($container);
     $this->expectException(ServiceNotFoundException::class);
     $container->get(BarService::class);
 }
 /**
  * setConfig
  *
  * Set the entity repository managers configuration
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceManager
  * @param \ArpEntityRepository\Service\EntityRepositoryManager $entityRepositoryManager
  */
 protected function setConfig(ServiceLocatorInterface $serviceManager, EntityRepositoryManager $entityRepositoryManager)
 {
     $config = $serviceManager->get('config');
     $key = static::CONFIG_KEY;
     if (isset($config[$key]) && is_array($config[$key])) {
         $config = new Config($config[$key]);
         $config->configureServiceManager($entityRepositoryManager);
     }
 }
 public function setUp()
 {
     $serviceManagerConfig = new Config(['factories' => ['SphinxSearch\\Db\\Adapter\\Adapter' => 'SphinxSearch\\Db\\Adapter\\AdapterServiceFactory'], 'aliases' => ['sphinxql' => 'SphinxSearch\\Db\\Adapter\\Adapter']]);
     $this->serviceManager = new ServiceManager();
     $serviceManagerConfig->configureServiceManager($this->serviceManager);
     $this->serviceManager->setService('Config', ['sphinxql' => $this->config]);
     $this->adapter = $this->serviceManager->get('sphinxql');
     $this->search = new Search($this->adapter);
     $this->sql = $this->search->getSql();
 }
 public function createService(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator)
 {
     $pm = $this->getManagerInstance();
     $appConfig = $serviceLocator->get('Config');
     $configKey = $this->getConfigKey();
     if (isset($appConfig[$configKey])) {
         $config = new Config($appConfig[$configKey]);
         $config->configureServiceManager($pm);
     }
     return $pm;
 }
Exemplo n.º 7
0
 public function testControllerLoadedCanBeInjectedWithValuesFromPeer()
 {
     $this->loader = $this->services->get('ControllerLoader');
     $config = array('invokables' => array('ZendTest\\Dispatchable' => 'ZendTest\\Mvc\\Service\\TestAsset\\Dispatchable'));
     $config = new Config($config);
     $config->configureServiceManager($this->loader);
     $controller = $this->loader->get('ZendTest\\Dispatchable');
     $this->assertInstanceOf('ZendTest\\Mvc\\Service\\TestAsset\\Dispatchable', $controller);
     $this->assertSame($this->services, $controller->getServiceLocator());
     $this->assertSame($this->services->get('EventManager'), $controller->getEventManager());
     $this->assertSame($this->services->get('ControllerPluginManager'), $controller->getPluginManager());
 }
Exemplo n.º 8
0
 public function onLoadModules(ModuleEvent $event)
 {
     //        /** @var ModuleManager $moduleManager */
     //        $moduleManager = $event->getTarget();
     /** @var ServiceManager $serviceLocator */
     $serviceLocator = $event->getParam('ServiceManager');
     $serviceConfig = ArrayUtils::merge($this->getConfig(false)['service_manager'], $this->getServiceConfig());
     $serviceConfig = new ServiceConfig($serviceConfig);
     $serviceConfig->configureServiceManager($serviceLocator);
     /** @var \Detail\VarCrypt\Listener\MultiEncryptorListener $encryptorListener */
     $encryptorListener = $serviceLocator->get('Detail\\VarCrypt\\Listener\\MultiEncryptorListener');
     $encryptorListener->onLoadModules($event);
     //        $moduleManager->getEventManager()->attachAggregate($encryptorListener);
 }
Exemplo n.º 9
0
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     /* @var ServiceManagerMock $serviceManager */
     parent::configureServiceManager($serviceManager);
     foreach ($this->getMocks() as $name => $spec) {
         if (is_array($spec) && array_key_exists('service', $spec)) {
             if (isset($spec['count_get'])) {
                 $serviceManager->setExpectedCallCount('get', $name, $spec['count_get']);
             }
             if (isset($spec['count_has'])) {
                 $serviceManager->setExpectedCallCount('has', $name, $spec['count_has']);
             }
             $spec = $spec['service'];
         }
         if (is_object($spec)) {
             $serviceManager->setService($name, $spec);
         } else {
             if (is_string($spec)) {
                 $serviceManager->setInvokableClass($name, $spec);
             } else {
                 $factory = new CreateInstanceFactory($spec[0], isset($spec[1]) ? $spec[1] : []);
                 $serviceManager->setFactory($name, $factory);
             }
         }
     }
 }
 public function applyConfig($serviceManager, $config)
 {
     foreach ($this->configKeys as $keyName => $thisManager) {
         $smConfig = array();
         if (isset($config[$keyName]) && is_array($config[$keyName])) {
             $smConfig = $config[$keyName];
         }
         // Get this service manager from the main service manager if it
         // isn't an instance already
         if (!$thisManager instanceof ServiceManager) {
             $thisManager = $serviceManager->get($thisManager);
         }
         // Apply the config to this service manager
         $serviceConfig = new ServiceConfig($smConfig);
         $serviceConfig->configureServiceManager($thisManager);
     }
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     parent::configureServiceManager($serviceManager);
     /*
      * Parameters:
      *
      * 'session.class'                     => 'Symfony\Component\HttpFoundation\Session\Session',
      * 'session.storage.class'             => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
      * 'session.flashbag.class'            => 'Symfony\Component\HttpFoundation\Session\Flash\FlashBag',
      * 'session.attribute_bag.class'       => 'Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag',
      * 'session.storage.native.class'      => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage',
      * 'session.handler.native_file.class' => 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler',
      */
     $config = $serviceManager->get('Config');
     $options = array_merge(array('auto_start' => false, 'storage_id' => 'session.storage.native', 'handler_id' => 'session.handler.native_file', 'name' => null, 'cookie_lifetime' => null, 'cookie_path' => null, 'cookie_domain' => null, 'cookie_secure' => null, 'cookie_httponly' => null, 'gc_divisor' => null, 'gc_probability' => null, 'gc_maxlifetime' => null, 'save_path' => null), isset($config['session']) ? $config['session'] : array());
     $storageOptions = $options;
     foreach (array('auto_start', 'storage_id', 'handler_id') as $k) {
         unset($storageOptions[$k]);
     }
     // session handler
     $serviceManager->setFactory('session.handler', function ($serviceManager) use($options) {
         $handlerID = $options['handler_id'];
         return $handlerID === null ? null : $serviceManager->get($handlerID);
     });
     // session storage native
     $serviceManager->setFactory('session.storage.native', function ($serviceManager) use($storageOptions) {
         // We need to strip out keys with a null value so symfony doesn't try and set things with a blank value
         $storageOptions = array_filter($storageOptions);
         return new NativeSessionStorage($storageOptions, $serviceManager->get('session.handler'));
     });
     // session flash bag
     $serviceManager->setFactory('session.flash_bag', function ($serviceManager) {
         return new FlashBag();
     });
     // session attribute bag
     $serviceManager->setFactory('session.attribute_bag', function ($serviceManager) {
         return new AttributeBag();
     });
     $that = $this;
     // session handler native file
     $serviceManager->setFactory('session.handler.native_file', function ($serviceManager) use($that, $storageOptions) {
         // We want absolute paths if we can
         if (null !== $storageOptions['save_path'] && !$that->isAbsolutePath($storageOptions['save_path'])) {
             $storageOptions['save_path'] = realpath($storageOptions['save_path']);
             // Basically if the realpath() failed then we revert back to null so default paths kick in
             if ($storageOptions['save_path'] === false) {
                 $storageOptions['save_path'] = null;
             }
         }
         return new NativeFileSessionHandler($storageOptions['save_path']);
     });
     // session
     $serviceManager->setFactory('session', function ($serviceManager) {
         $session = new Session($serviceManager->get('session.storage.native'), $serviceManager->get('session.attribute_bag'), $serviceManager->get('session.flash_bag'));
         //$session->start();
         return $session;
     });
 }
Exemplo n.º 12
0
 /**
  * Configure the provided container.
  *
  * Merges navigation_helpers configuration from the parent containers
  * config service with the configuration in this class, and uses that to
  * configure the provided service container (which should be the zend-view
  * `HelperPluginManager`).  with the service locator instance.
  *
  * Before configuring he provided container, it also adds a delegator
  * factory for the `Navigation` helper; the delegator uses the configuration
  * from this class to seed the `PluginManager` used by the `NavigationHelper`,
  * ensuring that any overrides provided via configuration are propagated
  * to it.
  *
  * @param  ServiceManager $serviceManager
  * @return ServiceManager
  */
 public function configureServiceManager(ServiceManager $container)
 {
     $services = $this->getParentContainer($container);
     if ($services->has('config')) {
         $this->mergeHelpersFromConfiguration($services->get('config'));
     }
     $this->injectNavigationDelegatorFactory(method_exists($container, 'configure'));
     parent::configureServiceManager($container);
     return $container;
 }
Exemplo n.º 13
0
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     parent::configureServiceManager($serviceManager);
     if (!$serviceManager instanceof LoggerManager) {
         return;
     }
     foreach ($this->getLoggers() as $name => $loggerOptions) {
         $serviceManager->setLogger($name, $loggerOptions);
     }
     foreach ($this->getHandlers() as $name => $handlerOptions) {
         $serviceManager->setHandler($name, $handlerOptions);
     }
 }
Exemplo n.º 14
0
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     if (!$serviceManager instanceof MailService) {
         throw new \DomainException('Can only configure instances of \\Core\\Mail\\MailService.');
     }
     parent::configureServiceManager($serviceManager);
     $serviceManager->setTransport($this->getTransport());
     $serviceManager->setFrom($this->getFrom());
     $serviceManager->setMailer($this->getMailer());
     /*
      * Development configuration
      */
     if ($recipients = $this->getOverrideRecipient()) {
         $serviceManager->setOverrideRecipient($recipients);
     }
 }
Exemplo n.º 15
0
 /**
  * Configure instance
  * 
  * @param array $options
  */
 protected function configure(array $options)
 {
     if (isset($options['actionPluginManager'])) {
         $config = new Config($options['actionPluginManager']);
         $config->configureServiceManager($this->getActionPlugins());
         unset($options['actionPluginManager']);
     }
     if (isset($options['storagePluginManager'])) {
         $config = new Config($options['storagePluginManager']);
         $config->configureServiceManager($this->getStoragePlugins());
         unset($options['storagePluginManager']);
     }
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'pluginName':
                 $this->setPluginName($name);
                 break;
             case 'limits':
                 $this->setLimits($value);
                 break;
             case 'storage':
                 $this->setStorage($value);
                 break;
             case 'useProxy':
                 $this->remoteAddress->setUseProxy($value);
                 break;
             case 'trustedProxies':
                 $this->remoteAddress->setTrustedProxies($value);
                 break;
         }
     }
 }
 public function __construct()
 {
     parent::__construct($this->configServiceManager());
 }
Exemplo n.º 17
0
 /**
  * @param ServiceManager $serviceManager
  */
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     parent::configureServiceManager($serviceManager);
 }
Exemplo n.º 18
0
 /**
  * Creates a view helper manager
  * @param ServiceLocatorInterface $sm
  * @return HelperPluginManager
  */
 protected function createHelperPluginManager(ServiceLocatorInterface $sm)
 {
     $factory = new ViewHelperManagerFactory();
     /** @var HelperPluginManager $helperManager */
     $helperManager = $factory->createService($sm);
     $config = new Config($this->getSpecificConfig($sm, 'view_helpers'));
     $config->configureServiceManager($helperManager);
     return $helperManager;
 }
 /**
  * Use merged configuration to configure service manager
  *
  * If the merged configuration has a non-empty, array 'service_manager'
  * key, it will be passed to a ServiceManager Config object, and
  * used to configure the service manager.
  *
  * @param  ModuleEvent $e
  * @throws Exception\RuntimeException
  * @return void
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     foreach ($this->serviceManagers as $key => $sm) {
         $smConfig = $this->mergeServiceConfiguration($key, $sm, $config);
         if (!$sm['service_manager'] instanceof ServiceManager) {
             if (!$this->defaultServiceManager->has($sm['service_manager'])) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $instance = $this->defaultServiceManager->get($sm['service_manager']);
             if (!$instance instanceof ServiceManager) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $sm['service_manager'] = $instance;
         }
         $serviceConfig = new ServiceConfig($smConfig);
         // The service listener is meant to operate during bootstrap, and, as such,
         // needs to be able to override existing configuration.
         $allowOverride = $sm['service_manager']->getAllowOverride();
         $sm['service_manager']->setAllowOverride(true);
         $serviceConfig->configureServiceManager($sm['service_manager']);
         $sm['service_manager']->setAllowOverride($allowOverride);
     }
 }
Exemplo n.º 20
0
 /**
  * Configure service container.
  *
  * Uses the configuration present in the instance to configure the provided
  * service container.
  *
  * Before doing so, it adds a "service" entry for the ServiceManager class,
  * pointing to the provided service container.
  *
  * @param ServiceManager $services
  * @return ServiceManager
  */
 public function configureServiceManager(ServiceManager $services)
 {
     $this->config['services'][ServiceManager::class] = $services;
     /*
             printf("Configuration prior to configuring servicemanager:\n");
             foreach ($this->config as $type => $list) {
        switch ($type) {
            case 'aliases':
            case 'delegators':
            case 'factories':
            case 'invokables':
            case 'lazy_services':
            case 'services':
            case 'shared':
                foreach (array_keys($list) as $name) {
                    printf("    %s (%s)\n", $name, $type);
                }
                break;
     
            case 'initializers':
            case 'abstract_factories':
                foreach ($list as $callable) {
                    printf("    %s (%s)\n", (is_object($callable) ? get_class($callable) : $callable), $type);
                }
                break;
     
            default:
                break;
        }
             }
     */
     // This is invoked as part of the bootstrapping process, and requires
     // the ability to override services.
     $services->setAllowOverride(true);
     parent::configureServiceManager($services);
     $services->setAllowOverride(false);
     return $services;
 }
Exemplo n.º 21
0
 protected function initalize()
 {
     if ($this->initalized) {
         return;
     }
     $this->initalized = true;
     $initalServiceManagerConfig = ArrayUtils::merge($this->defaultServiceManagerConfig, $this->serviceManagerConfig);
     if (isset($this->serviceManager)) {
         $serviceManager = $this->serviceManager;
     } else {
         $serviceManager = self::createServiceManager($initalServiceManagerConfig);
         $this->serviceManager = $serviceManager;
     }
     $serviceManager->setService('manifest', $this);
     //initalize extensions
     foreach ($this->extensionConfigs as $name => $extensionConfig) {
         if (!$extensionConfig) {
             unset($this->extensionConfigs[$name]);
             continue;
         }
         $this->expandExtensionConfig($name);
     }
     //merge all the configs
     $config = ['service_manager_config' => [], 'models' => []];
     foreach ($this->extensionConfigs as $extensionConfig) {
         $config = ArrayUtils::merge($config, array_intersect_key($extensionConfig, $config));
     }
     $this->serviceManagerConfig = ArrayUtils::merge($config['service_manager_config'], $initalServiceManagerConfig);
     $this->models = ArrayUtils::merge($config['models'], $this->models);
     //Apply service manager config
     $serviceManagerConfig = new Config($this->serviceManagerConfig);
     $serviceManager->setAllowOverride(true);
     $serviceManagerConfig->configureServiceManager($serviceManager);
     $serviceManager->setAllowOverride(false);
     //setup lazySubscriber configuration
     $this->lazySubscriberConfig = $this->getLazySubscirberConfig($serviceManager);
     $this->subscribers = ['subscriber.lazysubscriber'];
 }
 /**
  * Set up service manager and database configuration.
  *
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 protected function setUp()
 {
     $sManagerConfig = new Config(['abstract_factories' => ['SphinxSearch\\Db\\Adapter\\AdapterAbstractServiceFactory']]);
     $this->serviceManager = new ServiceManager();
     $sManagerConfig->configureServiceManager($this->serviceManager);
     $this->serviceManager->setService('Config', ['sphinxql' => ['adapters' => ['SphinxSearch\\Db\\Adapter\\One' => ['driver' => 'pdo_mysql'], 'SphinxSearch\\Db\\Adapter\\Two' => ['driver' => 'pdo_mysql']]]]);
 }
Exemplo n.º 23
0
 /**
  * Use merged configuration to configure service manager
  *
  * If the merged configuration has a non-empty, array 'service_manager'
  * key, it will be passed to a ServiceManager Config object, and
  * used to configure the service manager.
  *
  * @param  ModuleEvent $e
  * @throws Exception\RuntimeException
  * @return void
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     foreach ($this->serviceManagers as $key => $sm) {
         if (isset($config[$sm['config_key']]) && is_array($config[$sm['config_key']]) && !empty($config[$sm['config_key']])) {
             $this->serviceManagers[$key]['configuration']['merged_config'] = $config[$sm['config_key']];
         }
         // Merge all of the things!
         $smConfig = array();
         foreach ($this->serviceManagers[$key]['configuration'] as $configs) {
             if (isset($configs['configuration_classes'])) {
                 foreach ($configs['configuration_classes'] as $class) {
                     $configs = ArrayUtils::merge($configs, $this->serviceConfigToArray($class));
                 }
             }
             $smConfig = ArrayUtils::merge($smConfig, $configs);
         }
         if (!$sm['service_manager'] instanceof ServiceManager) {
             $instance = $this->defaultServiceManager->get($sm['service_manager']);
             if (!$instance instanceof ServiceManager) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $sm['service_manager'] = $instance;
         }
         $serviceConfig = new ServiceConfig($smConfig);
         $serviceConfig->configureServiceManager($sm['service_manager']);
     }
 }
Exemplo n.º 24
0
 protected function initalize()
 {
     if ($this->initalized) {
         return;
     }
     $this->initalized = true;
     if (isset($this->serviceManager)) {
         $serviceManager = $this->serviceManager;
     } else {
         $this->defaultServiceManagerConfig['delegators'][$this->documentManager] = ['documentManagerDelegatorFactory'];
         $serviceManager = self::createServiceManager($this->defaultServiceManagerConfig);
         $this->serviceManager = $serviceManager;
     }
     foreach ($this->extensionConfigs as $name => $extensionConfig) {
         $this->expandExtensionConfig($name, $extensionConfig);
     }
     //merge all the configs
     $config = ['service_manager_config' => [], 'filters' => [], 'documents' => [], 'cli_commands' => [], 'cli_helpers' => []];
     foreach ($this->extensionConfigs as $extensionConfig) {
         $config = ArrayUtils::merge($config, array_intersect_key($extensionConfig, $config));
     }
     $this->serviceManagerConfig = ArrayUtils::merge($config['service_manager_config'], $this->serviceManagerConfig);
     $this->filters = ArrayUtils::merge($config['filters'], $this->filters);
     $this->documents = ArrayUtils::merge($config['documents'], $this->documents);
     $this->cliCommands = ArrayUtils::merge($config['cli_commands'], $this->cliCommands);
     $this->cliHelpers = ArrayUtils::merge($config['cli_helpers'], $this->cliHelpers);
     //Apply service manager config
     $serviceManagerConfig = new Config($this->serviceManagerConfig);
     $serviceManagerConfig->configureServiceManager($serviceManager);
     //Make sure default service manager config is included in the main service manager config variable
     $this->serviceManagerConfig = ArrayUtils::merge($this->defaultServiceManagerConfig, $this->serviceManagerConfig);
     //create lazySubscriber configuration
     $lazySubscriberConfig = [];
     foreach ($this->extensionConfigs as $extensionConfig) {
         foreach ($extensionConfig['subscribers'] as $subscriber) {
             foreach ($serviceManager->get($subscriber)->getSubscribedEvents() as $event) {
                 if (!isset($lazySubscriberConfig[$event])) {
                     $lazySubscriberConfig[$event] = [];
                 }
                 $lazySubscriberConfig[$event][] = $subscriber;
             }
         }
         foreach ($this->subscribers as $subscriber) {
             foreach ($serviceManager->get($subscriber)->getSubscribedEvents() as $event) {
                 if (!isset($lazySubscriberConfig[$event])) {
                     $lazySubscriberConfig[$event] = [];
                 }
                 $lazySubscriberConfig[$event][] = $subscriber;
             }
         }
     }
     $this->lazySubscriberConfig = $lazySubscriberConfig;
     $this->subscribers = ['subscriber.lazySubscriber'];
     $serviceManager->setService('manifest', $this->toArray());
 }
 /**
  * Creates a view helper manager
  * @param ContainerInterface $container
  * @return HelperPluginManager
  */
 protected function createHelperPluginManager(ContainerInterface $container)
 {
     $factory = new ViewHelperManagerFactory();
     /** @var HelperPluginManager $helperManager */
     $helperManager = $factory->__invoke($container, ViewHelperManagerFactory::PLUGIN_MANAGER_CLASS);
     $config = new Config($this->getSpecificConfig($container, 'view_helpers'));
     $config->configureServiceManager($helperManager);
     return $helperManager;
 }
Exemplo n.º 26
0
 /**
  * @param null|array|ServiceManager $configurationOrServices
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return \Prooph\Processing\Environment\Environment
  */
 public static function setUp($configurationOrServices = null)
 {
     $env = null;
     //If neither a config array nor a ServiceManager is given, we initialize the variable with an empty array
     //Later in the set up the default config is merged with this empty array
     if (is_null($configurationOrServices)) {
         $configurationOrServices = [];
     }
     //Initialize the Environment
     if ($configurationOrServices instanceof ServiceManager) {
         //We assume that when the workflow processor service definition is missing
         //then the other services related to the workflow environment are also missing
         if (!$configurationOrServices->has(Definition::SERVICE_WORKFLOW_PROCESSOR)) {
             $servicesConfig = new Config(self::$defaultServicesConfig);
             $servicesConfig->configureServiceManager($configurationOrServices);
         }
         $env = new self(Zf2ServiceManagerProxy::proxy($configurationOrServices));
         //Check if the provided ServiceManager already has a configuration service available
         //so we make sure that we won't override it later but just merge it with the default environment config
         if ($env->services()->has('configuration')) {
             $configurationOrServices = $env->services()->get('configuration');
         } else {
             $configurationOrServices = [];
         }
     } elseif (is_array($configurationOrServices)) {
         //No external ServiceManager given, so we set up a new one
         $servicesConfig = [];
         if (isset($configurationOrServices['services'])) {
             $servicesConfig = $configurationOrServices['services'];
             unset($configurationOrServices['services']);
         }
         $servicesConfig = new Config(ArrayUtils::merge(self::$defaultServicesConfig, $servicesConfig));
         $env = new self(Zf2ServiceManagerProxy::proxy(new ServiceManager($servicesConfig)));
     }
     //This should never happen, but if for whatever reason a wrong $configurationOrServices was passed to the set up
     //we stop the process here
     if (is_null($env)) {
         throw new \InvalidArgumentException("Processing set up requires either a config array or a ready to use Zend\\ServiceManager");
     }
     //We proceed with merging and preparing the environment configuration
     $envConfig = ArrayUtils::merge(self::$defaultEnvConfig, $configurationOrServices);
     //The environment node name is used as target for the local channel, the config needs to be adapted accordingly.
     $envConfigReader = new ArrayReader($envConfig);
     $nodeName = $envConfigReader->stringValue('processing.node_name', Definition::DEFAULT_NODE_NAME);
     $localChannelTargets = $envConfigReader->arrayValue('processing.channels.local.targets');
     if (!in_array($nodeName, $localChannelTargets)) {
         $envConfig = ArrayUtils::merge($envConfig, ['processing' => ['channels' => ['local' => ['targets' => [$nodeName]]]]]);
     }
     $env->services()->set('configuration', $envConfig, true);
     if (!$env->services()->has('config')) {
         $env->services()->setAlias('config', 'configuration');
     }
     $env->services()->set(Definition::SERVICE_ENVIRONMENT, $env, true);
     //The node name is used as message bus target to address the workflow processor of the current environment
     //We alias the workflow processor service with the node name to ensure that the target can be resolved
     $env->services()->setAlias($nodeName, Definition::SERVICE_WORKFLOW_PROCESSOR);
     //The environment component ships with an own workflow engine implementation that uses the ServiceManager
     //to resolve the required message buses for the various targets
     $env->workflowEngine = new ServicesAwareWorkflowEngine($env->services());
     //Add an initializer which injects the local processor message buses whenever a workflow message handler
     //is requested from the ServiceManager
     $env->services()->addInitializer(new WorkflowProcessorBusesProvider());
     //After the set up routine is finished the plugin mechanism can be triggered
     foreach ($env->getConfig()->arrayValue('plugins') as $plugin) {
         if (!$plugin instanceof Plugin && !is_string($plugin)) {
             throw new \RuntimeException(sprintf("Invalid plugin detected: %s. Plugins should be instance of Prooph\\Processing\\Environment\\Plugin or a ServiceManager alias that resolves to a plugin", is_object($plugin) ? get_class($plugin) : gettype($plugin)));
         }
         if (is_string($plugin)) {
             $plugin = $env->services->get($plugin);
             if (!$plugin instanceof Plugin) {
                 throw new \RuntimeException(sprintf("Resolved plugin for alias %s does not implement Prooph\\Processing\\Environment\\Plugin"));
             }
         }
         $env->register($plugin);
     }
     return $env;
 }
Exemplo n.º 27
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));
 }
 /**
  * Test for Issue #134 - Test for specific mime_resolver alias
  *
  * @coversNothing
  */
 public function mimeResolverAliasTest()
 {
     $config = (include __DIR__ . '/../../../config/module.config.php');
     $serviceManagerConfig = new Config($config['service_manager']);
     $serviceManager = new ServiceManager();
     $serviceManagerConfig->configureServiceManager($serviceManager);
     $serviceManager->setService('config', $config);
     $this->assertTrue($serviceManager->has('mime_resolver'));
     $this->assertTrue(is_object($serviceManager->get('mime_resolver')));
 }