当前位置: 首页>>代码示例>>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;未经允许,请勿转载。