Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX Moved initialisation of injector to the start of Core.php to m…

…ake 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).
  • Loading branch information...
commit 77099ddf9d95eb4029caf3a35954472854a4d4c9 1 parent 56388ef
Marcus Nyeholt authored
View
24 control/injector/Injector.php
@@ -231,6 +231,30 @@ public function setObjectCreator($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
* of a particular type is injected, and what items should be injected
View
9 core/Core.php
@@ -249,6 +249,12 @@
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 @@
*/
Debug::loadErrorHandlers();
-// initialise the dependency injector
-$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
-Injector::inst($default_options);
///////////////////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS
View
6 tests/injector/InjectorTest.php
@@ -12,6 +12,12 @@
*/
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);
Please sign in to comment.
Something went wrong with that request. Please try again.