本文整理汇总了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');
}
示例2: testPassingInvalidDefinitionRaisesException
public function testPassingInvalidDefinitionRaisesException()
{
$di = new Di();
$this->setExpectedException('PHPUnit_Framework_Error');
$di->setDefinitionList(array('foo'));
}
示例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());
}
示例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);
}
示例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);
}
}
}
}
}
}
}