本文整理匯總了PHP中Injector::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP Injector::create方法的具體用法?PHP Injector::create怎麽用?PHP Injector::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Injector
的用法示例。
在下文中一共展示了Injector::create方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getConstraints
public function getConstraints()
{
// evaluate any configured constraints
$constraints = $this->owner->config()->get('constraints');
$allConstraints = array();
if (count($constraints)) {
foreach ($constraints as $fieldName => $info) {
// if we've only given one constraint, it'll be a string, so make it an array
if (is_string($info)) {
$info = array($info);
}
foreach ($info as $constraintClass => $config) {
// allow plain classes, without arrays
if (is_numeric($constraintClass)) {
$constraintClass = $config;
$config = array();
}
if (!is_array($config)) {
parse_str($config, $arr);
$config = $arr;
}
if (!class_exists($constraintClass)) {
$constraintClass = 'SilverStripeAustralia\\Constraints\\Constraints\\' . $constraintClass;
}
$constraint = $this->injector->create($constraintClass, $this->owner, $fieldName, $config);
$allConstraints[] = $constraint;
}
}
}
return $allConstraints;
}
開發者ID:helpfulrobot,項目名稱:silverstripe-australia-silverstripe-constraints,代碼行數:31,代碼來源:ConstraintsExtension.php
示例2: mockFactory
/**
* @test
* @profile
* @ignore(ignoreUntilFixed)
*/
public function mockFactory()
{
$mockException = Mock_Factory::mock('Components\\Test_Exception', array('test/unit/case/mock', 'Mocked Exception.'));
$mockExceptionDefault = Mock_Factory::mock('Components\\Test_Exception');
$mockRunner = Mock_Factory::mock('Components\\Test_Runner');
$mockListener = Mock_Factory::mock('Components\\Test_Listener');
$mockListener->when('onInitialize')->doReturn(true);
$mockListener->when('onExecute')->doReturn(true);
$mockListener->when('onTerminate')->doNothing();
assertTrue($mockListener->onExecute($mockRunner));
assertTrue($mockListener->onInitialize($mockRunner));
$mockLL->onTerminate($mockRunner);
assertEquals('test/unit/case/mock', $mockException->getNamespace());
assertEquals('Mocked Exception.', $mockException->getMessage());
assertEquals('test/exception', $mockExceptionDefault->getNamespace());
assertEquals('Test exception.', $mockExceptionDefault->getMessage());
$mockBindingModule = Mock_Factory::mock('Components\\Binding_Module');
$mockBindingModule->when('bind')->doAnswer(function (Binding_Module $self_, $type_) {
echo "Bound {$type_}\r\n";
return $self_->bind($type_);
});
$mockBindingModule->when('configure')->doAnswer(function (Binding_Module $self_) {
$self_->bind('Components\\Test_Runner')->toInstance(Test_Runner::get());
$self_->bind(Integer::TYPE)->toInstance(22)->named('boundInteger');
});
$injector = Injector::create($mockBindingModule);
assertSame(Test_Runner::get(), $injector->resolveInstance('Components\\Test_Runner'));
assertEquals(22, $injector->resolveInstance(Integer::TYPE, 'boundInteger'));
}
示例3: testCreateConfiggedObjectWithCustomConstructorArgs
public function testCreateConfiggedObjectWithCustomConstructorArgs()
{
// need to make sure that even if the config defines some constructor params,
// that we take our passed in constructor args instead
$injector = new Injector(array('locator' => 'InjectorTestConfigLocator'));
$item = $injector->create('ConfigConstructor', 'othervalue');
$this->assertEquals($item->property, 'othervalue');
}
示例4: testSameNamedSingeltonPrototype
public function testSameNamedSingeltonPrototype()
{
$injector = new Injector();
// get a singleton object
$object = $injector->get('NeedsBothCirculars');
$object->var = 'One';
$again = $injector->get('NeedsBothCirculars');
$this->assertEquals($again->var, 'One');
// create a NEW instance object
$new = $injector->create('NeedsBothCirculars');
$this->assertNull($new->var);
// this will trigger a problem below
$new->var = 'Two';
$again = $injector->get('NeedsBothCirculars');
$this->assertEquals($again->var, 'One');
}
示例5: testSimpleSingleton
public function testSimpleSingleton()
{
$injector = new Injector();
$one = $injector->create('CircularOne');
$two = $injector->create('CircularOne');
$this->assertFalse($one === $two);
$one = $injector->get('CircularTwo');
$two = $injector->get('CircularTwo');
$this->assertTrue($one === $two);
}
示例6: CachedFragment
/**
* Retrieve a cached fragment in the context of this page.
*
* @param string $name
* @return string
*/
public function CachedFragment($name)
{
$item = $this->injector->create('CachedFragment', $this->owner, $name);
return $item;
}
示例7: getInjector
/**
* @return \Components\Injector
*/
public function getInjector()
{
if (null === $this->m_injector) {
$this->m_injector = Injector::create($this->getBindingModule());
}
return $this->m_injector;
}