當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。