php Zend-ServiceManager-ServiceManager类(方法)实例源码

下面列出了php Zend-ServiceManager-ServiceManager 类(方法)源码代码实例,从而了解它的用法。

作者:gingerwfm    项目:wf-configurator-backen   
public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
 }

作者:acelay    项目:zf2-acyam   
public function testCreateService()
 {
     $sm = new ServiceManager();
     $sm->setService('Acelaya\\Yaml\\View\\Renderer\\YamlRenderer', new YamlRenderer());
     $service = $this->factory->createService($sm);
     $this->assertInstanceOf('Acelaya\\Yaml\\View\\Strategy\\YamlStrategy', $service);
 }

作者:retta    项目:zf2-for   
public function setUp()
 {
     $this->pluginManager = new RulePluginManager();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('MvcTranslator', new Translator());
     $this->pluginManager->setServiceLocator($serviceManager);
 }

作者:recommerc    项目:queue-manage   
/**
  * Init an instance of QueueWriter and configure an internal instance of ServiceManager
  *
  * @param array $config
  * @return QueueWriterInterface
  */
 public static function get(array $config)
 {
     $serviceConfig = (include dirname(dirname(dirname(__DIR__))) . '/config/services.config.php');
     $services = new ServiceManager(new Config($serviceConfig['service_manager']));
     $services->setService("Config", $config);
     return $services->get('recommerce.queue-manager.queue-writer');
 }

作者:debranov    项目:progra   
/**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->serviceManager = Bootstrap::getServiceManager();
     $this->doa = new Doa();
     $this->doa->setId(1);
     $program = new Program();
     $program->setId(1);
     $program->setProgram('Program');
     $this->doa->setProgram($program);
     $organisation = new Organisation();
     $organisation->setId(1);
     $organisation->setOrganisation("Organisation");
     $this->doa->setOrganisation($organisation);
     $this->authorizeService = $this->serviceManager->get('BjyAuthorize\\Service\\Authorize');
     if (!$this->authorizeService->getAcl()->hasResource($this->doa)) {
         $this->authorizeService->getAcl()->addResource($this->doa);
         $this->authorizeService->getAcl()->allow([], $this->doa, []);
     }
     /**
      * Add the resource on the fly
      */
     if (!$this->authorizeService->getAcl()->hasResource(new Doa())) {
         $this->authorizeService->getAcl()->addResource(new Doa());
     }
     $this->authorizeService->getAcl()->allow([], new Doa(), []);
     $this->doaLink = $this->serviceManager->get('viewhelpermanager')->get('programDoaLink');
     /**
      * Bootstrap the application to have the other information available
      */
     $application = $this->serviceManager->get('application');
     $application->bootstrap();
 }

作者:lucatum    项目:php-dependency-injection-benchmark   
public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
 {
     $serviceManager->setFactory('A', function () {
         return new A();
     });
     $serviceManager->setShared('A', false);
 }

作者:mt-olympu    项目:herme   
/**
  * @covers Hermes\Api\ClientFactory::createService
  */
 public function testCreateService()
 {
     $sm = new ServiceManager(new Config([]));
     $sm->setService('config', ['hermes' => ['uri' => 'http://localhost:8000', 'depth' => 0, 'headers' => [], 'http_client' => ['options' => []]]]);
     $client = $this->object->createService($sm);
     $this->assertInstanceOf(Client::class, $client);
 }

作者:acelay    项目:alejandrocelaya.co   
public function testInvoke()
 {
     $sm = new ServiceManager();
     $sm->setService('config', ['recaptcha' => ['private_key' => 'foo']]);
     $instance = $this->factory->__invoke($sm, '');
     $this->assertInstanceOf(ReCaptcha::class, $instance);
 }

作者:binarykitte    项目:zf2authwordpres   
public function wp_authenticate($hash, $password, ServiceManager $sm)
 {
     /** @var PasswordHash $wp_hasher */
     $wp_hasher = $sm->get('wp_hasher');
     $result = $wp_hasher->CheckPassword($password, $hash);
     return $result;
 }

作者:milqmedi    项目:mq-uti   
public function getServiceLocator(array $config = array())
 {
     $serviceLocator = new ServiceManager();
     $serviceLocator->setFactory('MQUtil\\Service\\ShortUrl', 'MQUtil\\Service\\ShortUrlFactory');
     $serviceLocator->setService('config', $config);
     return $serviceLocator;
 }

作者:kedward    项目:knc-erro   
public static function init()
 {
     if (is_readable(__DIR__ . '/config.php')) {
         $testConfig = (include __DIR__ . '/config.php');
     } else {
         $testConfig = (include __DIR__ . '/config.php.dist');
     }
     $moduleName = pathinfo(realpath(dirname(__DIR__)), PATHINFO_BASENAME);
     if (defined('MODULE_NAME')) {
         $moduleName = MODULE_NAME;
     }
     $zf2ModulePaths = array(dirname(dirname(__DIR__)));
     if ($path = static::findParentPath('vendor')) {
         $modulePaths[] = $path;
     }
     if (($path = static::findParentPath('module')) !== $modulePaths[0]) {
         $modulePaths[] = $path;
     }
     if (isset($additionalModulePaths)) {
         $zf2ModulePaths = array_merge($modulePaths, $additionalModulePaths);
     } else {
         $zf2ModulePaths = $modulePaths;
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     static::initAutoloader();
     $baseConfig = ['module_listener_options' => ['module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)], 'modules' => [$moduleName]];
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
 }

作者:aapth    项目:taggerzz-ne   
public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('zfcuser_module_options', new ModuleOptions());
     $factory = new ChangePasswordFormFactory();
     $this->assertInstanceOf('ZfcUser\\Form\\ChangePassword', $factory->createService($serviceManager));
 }

作者:DavidHav    项目:Ajast   
public function setUp()
 {
     $addressService = $this->getMockBuilder('Ajasta\\Address\\Service\\AddressService')->disableOriginalConstructor()->getMock();
     $this->serviceLocator = new ServiceManager();
     $this->serviceLocator->setService('Ajasta\\Address\\Service\\AddressService', $addressService);
     $this->serviceLocator->setService('Ajasta\\Locale', 'en-US');
 }

作者:antoineale    项目:TibetWebsit   
public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference()
 {
     $config = array('doctrine' => array('configuration' => array('test_default' => array('naming_strategy' => 'test_naming_strategy'))));
     $this->serviceManager->setService('Config', $config);
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\InvalidArgumentException');
     $this->factory->createService($this->serviceManager);
 }

作者:shitikovkiril    项目:zend-shop.co   
public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('HtImg\\Imagine', new Imagine());
     $factory = new ImageStrategyFactory();
     $this->assertInstanceOf('HtImgModule\\View\\Strategy\\ImageStrategy', $factory->createService($serviceManager));
 }

作者:samul    项目:vufind-er   
/**
  * Generic plugin manager factory (support method).
  *
  * @param ServiceManager $sm Service manager.
  * @param string         $ns VuFind namespace containing plugin manager
  *
  * @return object
  */
 public static function getGenericPluginManager(ServiceManager $sm, $ns)
 {
     $className = 'Finna\\' . $ns . '\\PluginManager';
     $configKey = strtolower(str_replace('\\', '_', $ns));
     $config = $sm->get('Config');
     return new $className(new \Zend\ServiceManager\Config($config['vufind']['plugin_managers'][$configKey]));
 }

作者:acelay    项目:alejandrocelaya.co   
public function testInvoke()
 {
     $sm = new ServiceManager();
     $sm->setService('config', ['translator' => []]);
     $instance = $this->factory->__invoke($sm, '');
     $this->assertInstanceOf(Translator::class, $instance);
 }

作者:shitikovkiril    项目:zend-shop.co   
public function testFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('HtImg\\ModuleOptions', new ModuleOptions());
     $factory = new CacheManagerFactory();
     $this->assertInstanceOf('HtImgModule\\Service\\CacheManager', $factory->createService($serviceManager));
 }

作者:esas    项目:dream-cm   
/**
  * Setup
  */
 protected function setUp()
 {
     // get service manager
     $this->serviceLocator = FileManagerBootstrap::getServiceLocator();
     // get base user model instance
     $this->userModel = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserBase');
 }

作者:esas    项目:dream-cm   
/**
  * Setup
  */
 protected function setUp()
 {
     // get service manager
     $this->serviceLocator = ApplicationBootstrap::getServiceLocator();
     // get base model instance
     $this->model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationBase');
 }


问题


面经


文章

微信
公众号

扫码关注公众号