本文整理汇总了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;
}
示例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);
}
示例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());
}