本文整理匯總了PHP中Injector::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP Injector::load方法的具體用法?PHP Injector::load怎麽用?PHP Injector::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Injector
的用法示例。
在下文中一共展示了Injector::load方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testCustomObjectCreator
public function testCustomObjectCreator()
{
$injector = new Injector();
$injector->setObjectCreator(new SSObjectCreator());
$config = array('OriginalRequirementsBackend', 'DummyRequirements' => array('class' => 'DummyRequirements(\'%$OriginalRequirementsBackend\')'));
$injector->load($config);
$requirements = $injector->get('DummyRequirements');
$this->assertEquals('OriginalRequirementsBackend', get_class($requirements->backend));
}
示例2: testTooManyArrayValues
/**
* @expectedException InvalidArgumentException
*/
public function testTooManyArrayValues()
{
$injector = new Injector();
$config = array('TestService' => array('class' => 'TestObject', 'calls' => array(array('method', array('args'), 'what is this?'))));
$injector->load($config);
$item = $injector->get('TestService');
}
示例3: testConvertServicePropertyOnCreate
public function testConvertServicePropertyOnCreate()
{
// make sure convert service property is not called on direct calls to create, only on configured
// declarations to avoid un-needed function calls
$injector = new Injector();
$item = $injector->create('ConstructableObject', '%$TestObject');
$this->assertEquals('%$TestObject', $item->property);
// do it again but have test object configured as a constructor dependency
$injector = new Injector();
$config = array('ConstructableObject' => array('constructor' => array('%$TestObject')));
$injector->load($config);
$item = $injector->get('ConstructableObject');
$this->assertTrue($item->property instanceof TestObject);
// and with a configured object defining TestObject to be something else!
$injector = new Injector(array('locator' => 'InjectorTestConfigLocator'));
$config = array('ConstructableObject' => array('constructor' => array('%$TestObject')));
$injector->load($config);
$item = $injector->get('ConstructableObject');
$this->assertTrue($item->property instanceof ConstructableObject);
$this->assertInstanceOf('OtherTestObject', $item->property->property);
}