BUGFIX Moved initialisation of injector to the start of Core.php to make sure that it is initialised correctly before additional code blocks reference it (in particular some of the code introduced by Sam that is triggered during add_extension).

This commit is contained in:
Marcus Nyeholt 2012-06-14 20:27:22 +10:00
parent 56388ef1d8
commit 77099ddf9d
3 changed files with 36 additions and 3 deletions

View File

@ -230,6 +230,30 @@ class Injector {
$this->objectCreator = $obj;
}
/**
* Accessor (for testing purposes)
* @return InjectionCreator
*/
public function getObjectCreator() {
return $this->objectCreator;
}
/**
* Set the configuration locator
* @param ServiceConfigurationLocator $configLocator
*/
public function setConfigLocator($configLocator) {
$this->configLocator = $configLocator;
}
/**
* Retrieve the configuration locator
* @return ServiceConfigurationLocator
*/
public function getConfigLocator() {
return $this->configLocator;
}
/**
* Add in a specific mapping that should be catered for on a type.
* This allows configuration of what should occur when an object

View File

@ -249,6 +249,12 @@ require_once 'core/manifest/ManifestFileFinder.php';
require_once 'core/manifest/TemplateLoader.php';
require_once 'core/manifest/TemplateManifest.php';
require_once 'core/manifest/TokenisedRegularExpression.php';
require_once 'control/injector/Injector.php';
// Initialise the dependency injector as soon as possible, as it is
// subsequently used by some of the following code
$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
Injector::inst($default_options);
///////////////////////////////////////////////////////////////////////////////
// MANIFEST
@ -286,9 +292,6 @@ if(Director::isLive()) {
*/
Debug::loadErrorHandlers();
// initialise the dependency injector
$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
Injector::inst($default_options);
///////////////////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS

View File

@ -12,6 +12,12 @@ define('TEST_SERVICES', dirname(__FILE__) . '/testservices');
*/
class InjectorTest extends SapphireTest {
public function testCorrectlyInitialised() {
$injector = Injector::inst();
$this->assertTrue($injector->getConfigLocator() instanceof SilverStripeServiceConfigurationLocator,
'If this fails, it is likely because the injector has been referenced BEFORE being initialised in Core.php');
}
public function testBasicInjector() {
$injector = new Injector();
$injector->setAutoScanProperties(true);