Skip to content
This repository
Browse code

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
authored June 14, 2012
24  control/injector/Injector.php
@@ -231,6 +231,30 @@ public function setObjectCreator($obj) {
231 231
 	}
232 232
 	
233 233
 	/**
  234
+	 * Accessor (for testing purposes)
  235
+	 * @return InjectionCreator
  236
+	 */
  237
+	public function getObjectCreator() {
  238
+		return $this->objectCreator;
  239
+	}
  240
+	
  241
+	/**
  242
+	 * Set the configuration locator 
  243
+	 * @param ServiceConfigurationLocator $configLocator 
  244
+	 */
  245
+	public function setConfigLocator($configLocator) {
  246
+		$this->configLocator = $configLocator;
  247
+	}
  248
+	
  249
+	/**
  250
+	 * Retrieve the configuration locator 
  251
+	 * @return ServiceConfigurationLocator 
  252
+	 */
  253
+	public function getConfigLocator() {
  254
+		return $this->configLocator;
  255
+	}
  256
+	
  257
+	/**
234 258
 	 * Add in a specific mapping that should be catered for on a type. 
235 259
 	 * This allows configuration of what should occur when an object
236 260
 	 * of a particular type is injected, and what items should be injected
9  core/Core.php
@@ -249,6 +249,12 @@
249 249
 require_once 'core/manifest/TemplateLoader.php';
250 250
 require_once 'core/manifest/TemplateManifest.php';
251 251
 require_once 'core/manifest/TokenisedRegularExpression.php';
  252
+require_once 'control/injector/Injector.php';
  253
+
  254
+// Initialise the dependency injector as soon as possible, as it is 
  255
+// subsequently used by some of the following code
  256
+$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
  257
+Injector::inst($default_options); 
252 258
 
253 259
 ///////////////////////////////////////////////////////////////////////////////
254 260
 // MANIFEST
@@ -286,9 +292,6 @@
286 292
  */
287 293
 Debug::loadErrorHandlers();
288 294
 
289  
-// initialise the dependency injector
290  
-$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
291  
-Injector::inst($default_options); 
292 295
 
293 296
 ///////////////////////////////////////////////////////////////////////////////
294 297
 // HELPER FUNCTIONS
6  tests/injector/InjectorTest.php
@@ -12,6 +12,12 @@
12 12
  */
13 13
 class InjectorTest extends SapphireTest {
14 14
 	
  15
+	public function testCorrectlyInitialised() {
  16
+		$injector = Injector::inst();
  17
+		$this->assertTrue($injector->getConfigLocator() instanceof SilverStripeServiceConfigurationLocator,
  18
+				'If this fails, it is likely because the injector has been referenced BEFORE being initialised in Core.php');
  19
+	}
  20
+	
15 21
 	public function testBasicInjector() {
16 22
 		$injector = new Injector();
17 23
 		$injector->setAutoScanProperties(true);

0 notes on commit 77099dd

Please sign in to comment.
Something went wrong with that request. Please try again.