mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #1186 from nyeholt/injector_configged_create
FIX issue with Injector::create not passing args
This commit is contained in:
commit
9ecea763c3
@ -773,6 +773,9 @@ class Injector {
|
|||||||
if (isset($this->specs[$name])) {
|
if (isset($this->specs[$name])) {
|
||||||
$spec = $this->specs[$name];
|
$spec = $this->specs[$name];
|
||||||
$this->updateSpecConstructor($spec);
|
$this->updateSpecConstructor($spec);
|
||||||
|
if ($constructorArgs) {
|
||||||
|
$spec['constructor'] = $constructorArgs;
|
||||||
|
}
|
||||||
return $this->instantiate($spec, $name);
|
return $this->instantiate($spec, $name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,6 +523,15 @@ class InjectorTest extends SapphireTest {
|
|||||||
|
|
||||||
$this->assertInstanceOf('OtherTestObject', $item->property->property);
|
$this->assertInstanceOf('OtherTestObject', $item->property->property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InjectorTestConfigLocator extends SilverStripeServiceConfigurationLocator implements TestOnly {
|
class InjectorTestConfigLocator extends SilverStripeServiceConfigurationLocator implements TestOnly {
|
||||||
@ -531,6 +540,10 @@ class InjectorTestConfigLocator extends SilverStripeServiceConfigurationLocator
|
|||||||
return array('class' => 'ConstructableObject', 'constructor' => array('%$OtherTestObject'));
|
return array('class' => 'ConstructableObject', 'constructor' => array('%$OtherTestObject'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($name == 'ConfigConstructor') {
|
||||||
|
return array('class' => 'ConstructableObject', 'constructor' => array('value'));
|
||||||
|
}
|
||||||
|
|
||||||
return parent::locateConfigFor($name);
|
return parent::locateConfigFor($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user