当前位置: 首页>>代码示例>>PHP>>正文


PHP ServiceManager::addInitializer方法代码示例

本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::addInitializer方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::addInitializer方法的具体用法?PHP ServiceManager::addInitializer怎么用?PHP ServiceManager::addInitializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\ServiceManager\ServiceManager的用法示例。


在下文中一共展示了ServiceManager::addInitializer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCreateWithInitializerObject

 public function testCreateWithInitializerObject()
 {
     $this->serviceManager->addInitializer(new TestAsset\FooInitializer(array('foo' => 'bar')));
     $this->serviceManager->setFactory('foo', function () {
         return new \stdClass();
     });
     $obj = $this->serviceManager->get('foo');
     $this->assertEquals('bar', $obj->foo);
 }
开发者ID:,项目名称:,代码行数:9,代码来源:

示例2: createServiceManager

 public function createServiceManager(array $config)
 {
     // create ServiceManager
     $serviceManager = new ServiceManager();
     // set an initializer for ServiceLocatorAwareInterface
     $serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($serviceLocator);
         }
     });
     // add $serviceManger to the config keys so we can configure it
     $this->configKeys = ['service_manager' => $serviceManager] + $this->configKeys;
     // add the pluginManagers to the ServiceManager
     foreach ($this->pluginManagers as $key => $className) {
         $serviceManager->setInvokableClass($key, $className);
     }
     // add Zend\Form's view helpers to the ViewHelperManager
     $viewHelperManager = $serviceManager->get('ViewHelperManager');
     $vhConfig = new \Zend\Form\View\HelperConfig();
     $vhConfig->configureServiceManager($viewHelperManager);
     // apply configuration
     $this->applyConfig($serviceManager, $config);
     return $serviceManager;
 }
开发者ID:akrabat,项目名称:rka-slim-zendform,代码行数:24,代码来源:ServiceManagerConfigurator.php

示例3: configureServiceManager

 /**
  * Configure the provided service manager instance with the configuration
  * in this class.
  *
  * In addition to using each of the internal properties to configure the
  * service manager, also adds an initializer to inject ServiceManagerAware
  * and ServiceLocatorAware classes with the service manager.
  *
  * @param ServiceManager $serviceManager
  */
 public function configureServiceManager(ServiceManager $serviceManager)
 {
     foreach ($this->invokables as $name => $class) {
         $serviceManager->setInvokableClass($name, $class);
     }
     foreach ($this->factories as $name => $factoryClass) {
         $serviceManager->setFactory($name, $factoryClass);
     }
     foreach ($this->abstractFactories as $factoryClass) {
         $serviceManager->addAbstractFactory($factoryClass);
     }
     foreach ($this->aliases as $name => $service) {
         $serviceManager->setAlias($name, $service);
     }
     foreach ($this->shared as $name => $value) {
         $serviceManager->setShared($name, $value);
     }
     $serviceManager->addInitializer(function ($instance) use($serviceManager) {
         if ($instance instanceof EventManagerAwareInterface) {
             if ($instance->getEventManager() instanceof EventManagerInterface) {
                 $instance->getEventManager()->setSharedManager($serviceManager->get('SharedEventManager'));
             } else {
                 $instance->setEventManager($serviceManager->get('EventManager'));
             }
         }
     });
     $serviceManager->addInitializer(function ($instance) use($serviceManager) {
         if ($instance instanceof ServiceManagerAwareInterface) {
             $instance->setServiceManager($serviceManager);
         }
     });
     $serviceManager->addInitializer(function ($instance) use($serviceManager) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($serviceManager);
         }
     });
     $serviceManager->setService('ServiceManager', $serviceManager);
 }
开发者ID:dragoonis,项目名称:framework,代码行数:48,代码来源:ServiceManagerConfig.php

示例4: testShouldRaiseExceptionIfInitializerClassIsNotAnInitializerInterfaceImplementation

 public function testShouldRaiseExceptionIfInitializerClassIsNotAnInitializerInterfaceImplementation()
 {
     $this->setExpectedException('Zend\ServiceManager\Exception\InvalidArgumentException');
     $result = $this->serviceManager->addInitializer(get_class($this));
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:5,代码来源:ServiceManagerTest.php

示例5: createServiceManager

 /**
  * Creates a service manager instnace
  *
  * @param  array                               $config
  * @return \Zend\ServiceManager\ServiceManager
  */
 public static function createServiceManager(array $config = [])
 {
     $serviceManager = new ServiceManager(new Config($config));
     $serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof ModelManagerAwareInterface) {
             $instance->setModelManager($serviceLocator->get('modelmanager'));
         }
     });
     $serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($serviceLocator);
         }
     });
     return $serviceManager;
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:21,代码来源:Manifest.php

示例6: createServiceManager

 public static function createServiceManager($config = [])
 {
     $serviceManager = new ServiceManager(new Config($config));
     $serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof DocumentManagerAwareInterface) {
             $instance->setDocumentManager($serviceLocator->get($serviceLocator->get('manifest')['document_manager']));
         }
     });
     $serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($serviceLocator);
         }
     });
     return $serviceManager;
 }
开发者ID:superdweebie,项目名称:doctrine-extensions,代码行数:15,代码来源:Manifest.php


注:本文中的Zend\ServiceManager\ServiceManager::addInitializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。