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


PHP ServiceManager::addDelegator方法代码示例

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


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

示例1: marshalServiceProvider

 /**
  * Iterates through all services of a service provider, seeding the container.
  *
  * For each service it:
  *
  * - adds the specified factory, if the service does not already exist.
  * - adds a delegator factory otherwise.
  *
  * @param ServiceProvider $provider
  * @param ServiceManager $container
  * @return ServiceManager
  * @throws RuntimeException if any factory listed is not callable.
  */
 private function marshalServiceProvider(ServiceProvider $provider, ServiceManager $container)
 {
     foreach ($provider->getServices() as $service => $factory) {
         $callable = $this->marshalCallable($provider, $factory, $service);
         if ($container->has($service)) {
             $container->addDelegator($service, $this->createDelegator($callable));
             continue;
         }
         $container->setFactory($service, $this->createFactory($callable));
     }
     return $container;
 }
开发者ID:phly,项目名称:zend-servicemanager-interop,代码行数:25,代码来源:ContainerInjector.php

示例2: testDelegatorFromCallback

 public function testDelegatorFromCallback()
 {
     $realService = $this->getMock('stdClass', array(), array(), 'RealService');
     $delegator = $this->getMock('stdClass', array(), array(), 'Delegator');
     $delegatorFactoryCallback = function ($serviceManager, $cName, $rName, $callback) use($delegator) {
         $delegator->real = call_user_func($callback);
         return $delegator;
     };
     $this->serviceManager->setFactory('foo-service', function () use($realService) {
         return $realService;
     });
     $this->serviceManager->addDelegator('foo-service', $delegatorFactoryCallback);
     $service = $this->serviceManager->create('foo-service');
     $this->assertSame($delegator, $service);
     $this->assertSame($realService, $service->real);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:16,代码来源:ServiceManagerTest.php

示例3: testAutoGenerateAndEvaluateProxies

 public function testAutoGenerateAndEvaluateProxies()
 {
     $serviceManager = new ServiceManager();
     $namespace = 'ZendTestProxy' . uniqid();
     $serviceManager->setService('Config', array('lazy_services' => array('class_map' => array('foo' => __CLASS__), 'proxies_namespace' => $namespace)));
     $serviceManager->setFactory('foo-delegator', 'Zend\\ServiceManager\\Proxy\\LazyServiceFactoryFactory');
     $serviceManager->setInvokableClass('foo', __CLASS__);
     $serviceManager->addDelegator('foo', 'foo-delegator');
     /* @var $proxy self|\ProxyManager\Proxy\ValueHolderInterface|\ProxyManager\Proxy\LazyLoadingInterface */
     $proxy = $serviceManager->create('foo');
     $proxyClassName = get_class($proxy);
     $this->assertInstanceOf('ProxyManager\\Proxy\\LazyLoadingInterface', $proxy);
     $this->assertInstanceOf(__CLASS__, $proxy);
     $this->assertStringMatchesFormat($namespace . '\\__PM__\\ZendTest\\ServiceManager\\Proxy\\LazyServiceFactoryFactoryTest%s', $proxyClassName);
     $this->assertFileNotExists(sys_get_temp_dir() . '/' . str_replace('\\', '', $proxyClassName) . '.php');
     $this->assertFalse($proxy->isProxyInitialized());
     $this->assertEquals($this->invalidConfigProvider(), $proxy->invalidConfigProvider());
     $this->assertTrue($proxy->isProxyInitialized());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:19,代码来源:LazyServiceFactoryFactoryTest.php


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