當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Di::newInstance方法代碼示例

本文整理匯總了PHP中Zend\Di\Di::newInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Di::newInstance方法的具體用法?PHP Di::newInstance怎麽用?PHP Di::newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Di\Di的用法示例。


在下文中一共展示了Di::newInstance方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _assembleEntities

 /**
  * Assemble entities
  *
  * @return void
  */
 private function _assembleEntities()
 {
     $this->_im->addAlias('Chat', 'App\\Bot\\Model\\Chat');
     $this->_im->addAlias('LastUpdate', 'App\\Bot\\Model\\LastUpdate');
     $this->_im->addAlias('UserIssue', 'App\\Redmine\\Model\\UserIssue');
     $this->_im->addAlias('UserKey', 'App\\Redmine\\Model\\UserKey');
     $this->_im->setParameters('Chat', ['collection' => $this->_di->newInstance('App\\Model\\Entity\\Collection')]);
     $this->_im->setParameters('LastUpdate', ['collection' => $this->_di->newInstance('App\\Model\\Entity\\Collection')]);
     $this->_im->setParameters('UserKey', ['collection' => $this->_di->newInstance('App\\Model\\Entity\\Collection')]);
 }
開發者ID:VaD1ke,項目名稱:redmine_telegram_notifier,代碼行數:15,代碼來源:DiC.php

示例2: newInstance

 /**
  * {@inheritDoc}
  */
 public function newInstance($name, array $params = array(), $isShared = true)
 {
     if (empty($params) && isset($this->compiledInstantiators[$name])) {
         $cb = $this->compiledInstantiators[$name];
         return $cb($this, $isShared);
     }
     return parent::newInstance($name, $params, $isShared);
 }
開發者ID:royopa,項目名稱:OcraDiCompiler,代碼行數:11,代碼來源:CompiledInstantiatorsDi.php

示例3: newInstance

 /**
  * Initialize and register the class via Dependency Injection
  *
  * @param string $alias
  * @param string $class
  * @param array  $parameters
  */
 public function newInstance($alias, $class, array $parameters = [])
 {
     try {
         $this->checkExists($alias);
         if (!empty($parameters)) {
             static::$di->instanceManager()->setParameters($class, $parameters);
         }
         $this->services[$alias] = static::$di->newInstance($class);
     } catch (\InvalidArgumentException $e) {
         throw $e;
     }
 }
開發者ID:waydelyle,項目名稱:mobicms,代碼行數:19,代碼來源:Container.php

示例4: doProxy

 /**
  * @param Di $locator
  * @return mixed
  */
 public function doProxy(Di $locator)
 {
     $options = $this->getOptions();
     $result = null;
     if ('get' === $options['method']) {
         $result = $locator->get($options['name'], $options['params']);
     } elseif ('newInstance' === $options['method']) {
         $result = $locator->newInstance($options['name'], $options['params'], $options['isShared']);
     } else {
         throw new InvalidArgumentException("'{$options['method']}' is undefined method'");
     }
     return $result;
 }
開發者ID:canaydogan,項目名稱:ukala,代碼行數:17,代碼來源:StandardProxy.php

示例5: newInstance

 /**
  * {@inheritDoc}
  * @return GeneratorInstance
  */
 public function newInstance($name, array $params = array(), $isShared = true)
 {
     $instance = parent::newInstance($name, $params, $isShared);
     if ($instance instanceof GeneratorInstance) {
         /* @var $instance GeneratorInstance */
         $instance->setShared($isShared);
         // When a callback is used, we don't know instance the class name.
         // That's why we assume $name as the instance alias
         if (null === $instance->getName()) {
             $instance->setAlias($name);
         }
     }
     return $instance;
 }
開發者ID:leonardovn86,項目名稱:zf2_basic2013,代碼行數:18,代碼來源:DependencyInjectorProxy.php

示例6: testDiWillInjectDefaultParameters

 /**
  * @group ZF2-142
  */
 public function testDiWillInjectDefaultParameters()
 {
     $di = new Di();
     $classDef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\ConstructorInjection\\OptionalParameters');
     $classDef->addMethod('__construct', true);
     $classDef->addMethodParameter('__construct', 'a', array('type' => false, 'required' => false, 'default' => null));
     $classDef->addMethodParameter('__construct', 'b', array('type' => false, 'required' => false, 'default' => 'defaultConstruct'));
     $classDef->addMethodParameter('__construct', 'c', array('type' => false, 'required' => false, 'default' => array()));
     $di->definitions()->addDefinition($classDef, false);
     $optionalParams = $di->newInstance('ZendTest\\Di\\TestAsset\\ConstructorInjection\\OptionalParameters');
     $this->assertSame(null, $optionalParams->a);
     $this->assertSame('defaultConstruct', $optionalParams->b);
     $this->assertSame(array(), $optionalParams->c);
 }
開發者ID:rajanlamic,項目名稱:IntTest,代碼行數:17,代碼來源:DiTest.php

示例7: testInjectionCanHandleMultipleInjectionsWithMultipleArguments

 public function testInjectionCanHandleMultipleInjectionsWithMultipleArguments()
 {
     $definitionList = new DefinitionList(array($classdef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\InjectionClasses\\A'), new Definition\RuntimeDefinition()));
     $classdef->addMethod('injectSplitDependency');
     $classdef->addMethodParameter('injectSplitDependency', 'b', array('required' => true, 'type' => 'ZendTest\\Di\\TestAsset\\InjectionClasses\\B'));
     $classdef->addMethodParameter('injectSplitDependency', 'somestring', array('required' => true, 'type' => null));
     /**
      * First test that this works with a single call
      */
     $di = new Di($definitionList);
     $di->instanceManager()->setInjections('ZendTest\\Di\\TestAsset\\InjectionClasses\\A', array('injectSplitDependency' => array('b' => 'ZendTest\\Di\\TestAsset\\InjectionClasses\\B', 'somestring' => 'bs-id')));
     $a = $di->newInstance('ZendTest\\Di\\TestAsset\\InjectionClasses\\A');
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\InjectionClasses\\B', $a->bs[0]);
     $this->assertEquals('bs-id', $a->bs[0]->id);
     /**
      * Next test that this works with multiple calls
      */
     $di = new Di($definitionList);
     $di->instanceManager()->setInjections('ZendTest\\Di\\TestAsset\\InjectionClasses\\A', array('injectSplitDependency' => array(array('b' => 'ZendTest\\Di\\TestAsset\\InjectionClasses\\B', 'somestring' => 'bs-id'), array('b' => 'ZendTest\\Di\\TestAsset\\InjectionClasses\\C', 'somestring' => 'bs-id-for-c'))));
     $a = $di->newInstance('ZendTest\\Di\\TestAsset\\InjectionClasses\\A');
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\InjectionClasses\\B', $a->bs[0]);
     $this->assertEquals('bs-id', $a->bs[0]->id);
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\InjectionClasses\\C', $a->bs[1]);
     $this->assertEquals('bs-id-for-c', $a->bs[1]->id);
 }
開發者ID:rafalwrzeszcz,項目名稱:zf2,代碼行數:25,代碼來源:DiTest.php

示例8: create

 /**
  * Create new object instance
  *
  * @param string $className
  * @param array $arguments
  * @param bool $isShared
  * @return object
  */
 public function create($className, array $arguments = array(), $isShared = true)
 {
     $object = $this->_di->newInstance($className, $arguments, $isShared);
     return $object;
 }
開發者ID:nickimproove,項目名稱:magento2,代碼行數:13,代碼來源:Zend.php

示例9: testNewInstanceThrowsExceptionWhenEnteringInMiddleOfCircularDependency

    /**
     * Test for Circular Dependencies (case 2)
     * 
     * C->D, D->E, E->C
     * @group CircularDependencyCheck
     */
    public function testNewInstanceThrowsExceptionWhenEnteringInMiddleOfCircularDependency()
    {
        $di = new Di();

        $this->setExpectedException(
            'Zend\Di\Exception\CircularDependencyException',
            'Circular dependency detected: ZendTest\Di\TestAsset\CircularClasses\C depends on ZendTest\Di\TestAsset\CircularClasses\D and viceversa'
        );
        $di->newInstance('ZendTest\Di\TestAsset\CircularClasses\D');
    }
開發者ID:rickogden,項目名稱:zf2,代碼行數:16,代碼來源:DiTest.php


注:本文中的Zend\Di\Di::newInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。