本文整理汇总了PHP中Container::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::newInstance方法的具体用法?PHP Container::newInstance怎么用?PHP Container::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container::newInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNewInstance
/**
*
* Tests that a class can be instantiated through the Container.
*
* @param string $class The expected class.
*
* @return null
*
* @dataProvider provideNewInstance
*
*/
public function testNewInstance($class, array $params = array(), array $setter = array())
{
if (!$class) {
$this->markTestSkipped('No class name passed for testNewInstance().');
}
$this->assertInstanceOf($class, $this->di->newInstance($class, $params, $setter));
}
示例2: testNewInstanceWithOverride
public function testNewInstanceWithOverride()
{
$instance = $this->container->newInstance('Aura\\Di\\MockParentClass', ['foo' => 'dib']);
$expect = 'dib';
$actual = $instance->getFoo();
$this->assertSame($expect, $actual);
}
示例3: newInstance
/**
*
* Creates a new DI container, adds pre-existing service objects, applies
* Config classes to define() services, locks the container, and applies
* the Config instances to modify() services.
*
* @param array $services Pre-existing service objects to set into the
* container.
*
* @param array $config_classes A list of Config classes to instantiate and
* invoke for configuring the container.
*
* @param bool $auto_resolve Enable or disable auto-resolve after the
* define() step?
*
* @return Container
*
*/
public function newInstance(array $services = array(), array $config_classes = array(), $auto_resolve = self::ENABLE_AUTO_RESOLVE)
{
$di = new Container(new Factory());
$di->setAutoResolve($auto_resolve);
foreach ($services as $key => $val) {
$di->set($key, $val);
}
$configs = array();
foreach ($config_classes as $class) {
$config = $di->newInstance($class);
$config->define($di);
$configs[] = $config;
}
$di->lock();
foreach ($configs as $config) {
$config->modify($di);
}
return $di;
}