mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
56388ef1d8
commit
77099ddf9d
@ -230,6 +230,30 @@ class Injector {
|
|||||||
$this->objectCreator = $obj;
|
$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.
|
* Add in a specific mapping that should be catered for on a type.
|
||||||
* This allows configuration of what should occur when an object
|
* This allows configuration of what should occur when an object
|
||||||
|
@ -249,6 +249,12 @@ require_once 'core/manifest/ManifestFileFinder.php';
|
|||||||
require_once 'core/manifest/TemplateLoader.php';
|
require_once 'core/manifest/TemplateLoader.php';
|
||||||
require_once 'core/manifest/TemplateManifest.php';
|
require_once 'core/manifest/TemplateManifest.php';
|
||||||
require_once 'core/manifest/TokenisedRegularExpression.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
|
// MANIFEST
|
||||||
@ -286,9 +292,6 @@ if(Director::isLive()) {
|
|||||||
*/
|
*/
|
||||||
Debug::loadErrorHandlers();
|
Debug::loadErrorHandlers();
|
||||||
|
|
||||||
// initialise the dependency injector
|
|
||||||
$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
|
|
||||||
Injector::inst($default_options);
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// HELPER FUNCTIONS
|
// HELPER FUNCTIONS
|
||||||
|
@ -12,6 +12,12 @@ define('TEST_SERVICES', dirname(__FILE__) . '/testservices');
|
|||||||
*/
|
*/
|
||||||
class InjectorTest extends SapphireTest {
|
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() {
|
public function testBasicInjector() {
|
||||||
$injector = new Injector();
|
$injector = new Injector();
|
||||||
$injector->setAutoScanProperties(true);
|
$injector->setAutoScanProperties(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user