當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。