createService() public method

For use with zend-servicemanager v2; proxies to __invoke().
public createService ( Zend\ServiceManager\ServiceLocatorInterface $container ) : Zend\ModuleManager\ModuleManager
$container Zend\ServiceManager\ServiceLocatorInterface
return Zend\ModuleManager\ModuleManager
コード例 #1
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $moduleManager = parent::createService($serviceLocator);
     $events = $moduleManager->getEventManager();
     $events->attach(ModuleEvent::EVENT_LOAD_MODULES, array($this, 'onLoadModules'), 1000);
     return $moduleManager;
 }
コード例 #2
0
 /**
  * Creates service.
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return \Zend\ModuleManager\ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $applicationConfig = $serviceLocator->get('ApplicationConfig');
     $moduleManager = parent::createService($serviceLocator);
     if (empty($applicationConfig['tayo_module_file']) === false) {
         $extraModules = Factory::fromFile($applicationConfig['tayo_module_file']);
         $modules = $moduleManager->getModules();
         $moduleManager->setModules(array_merge($modules, $extraModules));
     }
     return $moduleManager;
 }
コード例 #3
0
 /**
  * @expectedException \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
  */
 public function testInitLoadsEnvironmentVariablesFromWorkingDirectory()
 {
     $serviceLocator = new ServiceManager();
     $serviceLocator->setService('ApplicationConfig', array('module_listener_options' => array(), 'modules' => array('Abacaphiliac\\ZendPhpDotEnv')));
     $serviceLocator->setFactory('EventManager', new EventManagerFactory());
     $serviceLocator->setService('SharedEventManager', new SharedEventManager());
     $serviceLocator->setFactory('ServiceListener', '\\Zend\\Mvc\\Service\\ServiceListenerFactory');
     $moduleManagerFactory = new ModuleManagerFactory();
     $moduleManager = $moduleManagerFactory->createService($serviceLocator);
     $module = new Module($constant = null, $variable = null, $file = '.testEnv');
     $module->init($moduleManager);
     $moduleManager->getEventManager()->trigger(new ModuleEvent(ModuleEvent::EVENT_LOAD_MODULE));
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  *
  * @return ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('ApplicationConfig');
     $manager = parent::createService($serviceLocator);
     if (empty($config['modules_conditional'])) {
         return $manager;
     }
     $modules = $manager->getModules();
     foreach ($config['modules_conditional'] as $name => $closure) {
         if (!in_array($name, $modules)) {
             $modules[] = $name;
         }
     }
     $manager->setModules($modules);
     return $manager;
 }
コード例 #5
0
 /**
  * Creates and returns the module manager
  *
  * Instantiates the default module listeners, providing them configuration
  * from the "module_listener_options" key of the ApplicationConfig
  * service. Also sets the default config glob path.
  *
  * Module manager is instantiated and provided with an EventManager, to which
  * the default listener aggregate is attached. The ModuleEvent is also created
  * and attached to the module manager.
  *
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\ModuleManager\ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $moduleManager = parent::createService($serviceLocator);
     $modules = $moduleManager->getModules();
     $db = $serviceLocator->get('Zend\\Db\\Adapter\\Adapter');
     $platform = $db->getPlatform();
     $query = $db->query('
         SELECT ' . $platform->quoteIdentifier('module') . '
           FROM ' . $platform->quoteIdentifier('module') . '
          WHERE ' . $platform->quoteIdentifier('enabled') . '
     ');
     foreach ($query->execute() as $row) {
         $modules[] = $row['module'];
     }
     $moduleManager->getEventManager()->attach(new LoaderListener($db), -999);
     return $moduleManager->setModules($modules);
 }
コード例 #6
0
 /**
  * {@inheritDoc}
  *
  * @return ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $configuration = $serviceLocator->get('ApplicationConfig');
     $conditionResolvers = array();
     if (isset($configuration['modules_condition_resolvers'])) {
         $conditionResolvers = $configuration['modules_condition_resolvers'];
     }
     $moduleManager = parent::createService($serviceLocator);
     $modules = $moduleManager->getModules();
     foreach ($conditionResolvers as $module => $conditionResolver) {
         if (!in_array($module, $modules)) {
             continue;
         }
         $resolver = $serviceLocator->get($conditionResolver);
         if (!$resolver instanceof ConditionResolverInterface) {
             continue;
         }
         if (!$resolver->resolve()) {
             unset($modules[array_search($module, $modules)]);
         }
     }
     $moduleManager->setModules($modules);
     return $moduleManager;
 }