本文整理汇总了PHP中Zend\Di\Di::injectDependencies方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::injectDependencies方法的具体用法?PHP Di::injectDependencies怎么用?PHP Di::injectDependencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Di\Di
的用法示例。
在下文中一共展示了Di::injectDependencies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* @param $instance
*/
public function initialize($instance, ServiceLocatorInterface $serviceLocator)
{
$instanceManager = $this->di->instanceManager;
$this->di->instanceManager = $this->diInstanceManagerProxy;
try {
$this->di->injectDependencies($instance);
$this->di->instanceManager = $instanceManager;
} catch (\Exception $e) {
$this->di->instanceManager = $instanceManager;
throw $e;
}
}
示例2: __invoke
/**
* Initialize an instance via zend-di.
*
* @param mixed|ContainerInterface $first Container when under
* zend-servicemanager v3, instance to initialize otherwise.
* @param ContainerInterface|mixed $second Instance to initialize when
* under zend-servicemanager v3, container otherwise.
* @return void
*/
public function __invoke($first, $second)
{
if ($first instanceof AbstractPluginManager || $second instanceof ContainerInterface) {
$instance = $first;
} else {
$instance = $second;
}
$instanceManager = $this->di->instanceManager;
$this->di->instanceManager = $this->diInstanceManagerProxy;
try {
$this->di->injectDependencies($instance);
} catch (Exception $e) {
throw $e;
} finally {
$this->di->instanceManager = $instanceManager;
}
}
示例3: testDiWillInjectDependenciesForInstance
public function testDiWillInjectDependenciesForInstance()
{
$di = new Di();
// for setter injection, the dependency is not required, thus it must be forced
$classDef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\SetterInjection\\B');
$classDef->addMethod('setA', true);
$di->definitions()->addDefinition($classDef, false);
// top of stack b/c Runtime is already there
$b = new TestAsset\SetterInjection\B();
$di->injectDependencies($b);
$this->assertInstanceOf('ZendTest\\Di\\TestAsset\\SetterInjection\\A', $b->a);
}