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


PHP Di::setDefinitionList方法代码示例

本文整理汇总了PHP中Zend\Di\Di::setDefinitionList方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::setDefinitionList方法的具体用法?PHP Di::setDefinitionList怎么用?PHP Di::setDefinitionList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Di\Di的用法示例。


在下文中一共展示了Di::setDefinitionList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param string $definitionsFile
  * @param Zend\Di\Di $diInstance
  */
 public function __construct($definitionsFile = null, Zend\Di\Di $diInstance = null)
 {
     Magento_Profiler::start('di');
     if (is_file($definitionsFile) && is_readable($definitionsFile)) {
         $definition = new Magento_Di_Definition_ArrayDefinition_Zend(unserialize(file_get_contents($definitionsFile)));
     } else {
         $definition = new Magento_Di_Definition_RuntimeDefinition_Zend();
     }
     $this->_di = $diInstance ? $diInstance : new Magento_Di();
     $this->_di->setDefinitionList(new Magento_Di_DefinitionList_Zend($definition));
     $this->_di->instanceManager()->addSharedInstance($this, 'Magento_ObjectManager');
     Magento_Profiler::stop('di');
 }
开发者ID:nickimproove,项目名称:magento2,代码行数:17,代码来源:Zend.php

示例2: testPassingInvalidDefinitionRaisesException

    public function testPassingInvalidDefinitionRaisesException()
    {
        $di = new Di();

        $this->setExpectedException('PHPUnit_Framework_Error');
        $di->setDefinitionList(array('foo'));
    }
开发者ID:noirsoldats,项目名称:zf2,代码行数:7,代码来源:DiTest.php

示例3: testDiConstructorCanTakeDependencies

 public function testDiConstructorCanTakeDependencies()
 {
     $dl = new DefinitionList(array());
     $im = new InstanceManager();
     $cg = new Config(array());
     $di = new Di($dl, $im, $cg);
     $this->assertSame($dl, $di->definitions());
     $this->assertSame($im, $di->instanceManager());
     $di->setDefinitionList($dl);
     $di->setInstanceManager($im);
     $this->assertSame($dl, $di->definitions());
     $this->assertSame($im, $di->instanceManager());
 }
开发者ID:nieldm,项目名称:zf2,代码行数:13,代码来源:DiTest.php

示例4: testGetWithParamsWillUseSharedInstance

 /**
  * @group SharedInstance
  */
 public function testGetWithParamsWillUseSharedInstance()
 {
     $di = new Di();
     $sharedInstanceClass = 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\A';
     $retrievedInstanceClass = 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\C';
     // Provide definitions for $retrievedInstanceClass, but not for $sharedInstanceClass.
     $arrayDefinition = array($retrievedInstanceClass => array('supertypes' => array(), 'instantiator' => '__construct', 'methods' => array('__construct' => true), 'parameters' => array('__construct' => array("{$retrievedInstanceClass}::__construct:0" => array('a', $sharedInstanceClass, true, NULL), "{$retrievedInstanceClass}::__construct:1" => array('params', NULL, false, array())))));
     // This also disables scanning of class A.
     $di->setDefinitionList(new DefinitionList(new Definition\ArrayDefinition($arrayDefinition)));
     $di->instanceManager()->addSharedInstance(new $sharedInstanceClass(), $sharedInstanceClass);
     $returnedC = $di->get($retrievedInstanceClass, array('params' => array('test')));
     $this->assertInstanceOf($retrievedInstanceClass, $returnedC);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:16,代码来源:DiTest.php

示例5: configureDefinition

 /**
  * @param Di    $di
  * @param array $definition
  */
 public function configureDefinition(Di $di, $definition)
 {
     foreach ($definition as $definitionType => $definitionData) {
         switch ($definitionType) {
             case 'compiler':
                 foreach ($definitionData as $filename) {
                     if (is_readable($filename)) {
                         $di->definitions()->addDefinition(new ArrayDefinition(include $filename), false);
                     }
                 }
                 break;
             case 'runtime':
                 if (isset($definitionData['enabled']) && !$definitionData['enabled']) {
                     // Remove runtime from definition list if not enabled
                     $definitions = array();
                     foreach ($di->definitions() as $definition) {
                         if (!$definition instanceof RuntimeDefinition) {
                             $definitions[] = $definition;
                         }
                     }
                     $definitionList = new DefinitionList($definitions);
                     $di->setDefinitionList($definitionList);
                 } elseif (isset($definitionData['use_annotations']) && $definitionData['use_annotations']) {
                     /* @var $runtimeDefinition Definition\RuntimeDefinition */
                     $runtimeDefinition = $di->definitions()->getDefinitionByType('\\Zend\\Di\\Definition\\RuntimeDefinition');
                     $runtimeDefinition->getIntrospectionStrategy()->setUseAnnotations(true);
                 }
                 break;
             case 'class':
                 foreach ($definitionData as $className => $classData) {
                     $classDefinitions = $di->definitions()->getDefinitionsByType('Zend\\Di\\Definition\\ClassDefinition');
                     foreach ($classDefinitions as $classDefinition) {
                         if (!$classDefinition->hasClass($className)) {
                             unset($classDefinition);
                         }
                     }
                     if (!isset($classDefinition)) {
                         $classDefinition = new Definition\ClassDefinition($className);
                         $di->definitions()->addDefinition($classDefinition, false);
                     }
                     foreach ($classData as $classDefKey => $classDefData) {
                         switch ($classDefKey) {
                             case 'instantiator':
                                 $classDefinition->setInstantiator($classDefData);
                                 break;
                             case 'supertypes':
                                 $classDefinition->setSupertypes($classDefData);
                                 break;
                             case 'methods':
                             case 'method':
                                 foreach ($classDefData as $methodName => $methodInfo) {
                                     if (isset($methodInfo['required'])) {
                                         $classDefinition->addMethod($methodName, $methodInfo['required']);
                                         unset($methodInfo['required']);
                                     }
                                     foreach ($methodInfo as $paramName => $paramInfo) {
                                         $classDefinition->addMethodParameter($methodName, $paramName, $paramInfo);
                                     }
                                 }
                                 break;
                             default:
                                 $methodName = $classDefKey;
                                 $methodInfo = $classDefData;
                                 if (isset($classDefData['required'])) {
                                     $classDefinition->addMethod($methodName, $methodInfo['required']);
                                     unset($methodInfo['required']);
                                 }
                                 foreach ($methodInfo as $paramName => $paramInfo) {
                                     $classDefinition->addMethodParameter($methodName, $paramName, $paramInfo);
                                 }
                         }
                     }
                 }
         }
     }
 }
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:80,代码来源:Config.php


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