本文整理匯總了PHP中Parameter::named方法的典型用法代碼示例。如果您正苦於以下問題:PHP Parameter::named方法的具體用法?PHP Parameter::named怎麽用?PHP Parameter::named使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Parameter
的用法示例。
在下文中一共展示了Parameter::named方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_RegisterWithFactoryParam_ResolveNamed
public function test_RegisterWithFactoryParam_ResolveNamed()
{
$counter = 0;
$this->registerType('Test\\ClassA')->named('test')->onActivated(function () use(&$counter) {
$counter++;
});
$this->registerType('ClassN22')->withParams(Parameter::named('test'));
$c = $this->resolve('ClassN22');
$this->assertEquals(0, $counter);
$c->a->createInstance();
$this->assertEquals(1, $counter);
}
示例2: testResolvingNamedParameters
public function testResolvingNamedParameters()
{
$this->builder->registerType('ClassZ')->withParams(Parameter::def(), 'z', Parameter::named('test2'));
$this->builder->registerType('ClassE')->withParams('test1');
$this->builder->registerType('ClassE')->withParams('test2')->named('test2');
$container = $this->builder->build();
$z = $container->resolve('ClassZ');
$this->assertEquals('test1', $container->resolve('ClassE')->value);
$this->assertEquals('test2', $container->resolveNamed('test2')->value);
$this->assertEquals('test1', $z->e1->value);
$this->assertEquals('z', $z->value);
$this->assertEquals('test2', $z->e2->value);
}