当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::newInstance方法代码示例

本文整理汇总了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));
 }
开发者ID:watsonad,项目名称:opendocman,代码行数:18,代码来源:AbstractContainerTest.php

示例2: testNewInstanceWithOverride

 public function testNewInstanceWithOverride()
 {
     $instance = $this->container->newInstance('Aura\\Di\\MockParentClass', ['foo' => 'dib']);
     $expect = 'dib';
     $actual = $instance->getFoo();
     $this->assertSame($expect, $actual);
 }
开发者ID:walterjrp,项目名称:form-builder,代码行数:7,代码来源:ContainerTest.php

示例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;
 }
开发者ID:watsonad,项目名称:opendocman,代码行数:37,代码来源:ContainerBuilder.php


注:本文中的Container::newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。