diff --git a/control/injector/Injector.php b/control/injector/Injector.php index 3e747995e..37d758480 100644 --- a/control/injector/Injector.php +++ b/control/injector/Injector.php @@ -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 diff --git a/core/Core.php b/core/Core.php index 993011e3b..77cc41f1f 100644 --- a/core/Core.php +++ b/core/Core.php @@ -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 diff --git a/tests/injector/InjectorTest.php b/tests/injector/InjectorTest.php index a4cd9dfeb..01c6a40f5 100644 --- a/tests/injector/InjectorTest.php +++ b/tests/injector/InjectorTest.php @@ -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);