Skip to content
This repository
Browse code

MINOR Use injector for creating Member_GroupSet object

MINOR Use injector for creating many many list objects

MINOR Use injector for creating objects from within the DataList

MINOR Use Injector::inst() for creating objects; cannot rely on this->injector being present due to many classes being created with 'new', so use inst() directly

MINOR Remove injector autoset property for now; automatically setting it breaks a few test cases that don't know about it for now, and it's not needed just yet
  • Loading branch information...
commit 82a1e7d2823583a8f9f937ceb96864132ccbb43f 1 parent 9898cd9
authored
2  core/Core.php
@@ -283,7 +283,7 @@
283 283
 
284 284
 // initialise the dependency injector
285 285
 $default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
286  
-Injector::inst($default_options)->addAutoProperty('injector', Injector::inst()); 
  286
+Injector::inst($default_options); 
287 287
 
288 288
 ///////////////////////////////////////////////////////////////////////////////
289 289
 // HELPER FUNCTIONS
6  dev/SapphireTest.php
@@ -829,17 +829,17 @@ function resetDBSchema($includeExtraDataObjects = false) {
829 829
 	 */
830 830
 	function logInWithPermission($permCode = "ADMIN") {
831 831
 		if(!isset($this->cache_generatedMembers[$permCode])) {
832  
-			$group = new Group();
  832
+			$group = Injector::inst()->create('Group');
833 833
 			$group->Title = "$permCode group";
834 834
 			$group->write();
835 835
 
836  
-			$permission = new Permission();
  836
+			$permission = Injector::inst()->create('Permission');
837 837
 			$permission->Code = $permCode;
838 838
 			$permission->write();
839 839
 			$group->Permissions()->add($permission);
840 840
 			
841 841
 			$member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
842  
-			if(!$member) $member = new Member();
  842
+			if(!$member) $member = Injector::inst()->create('Member');
843 843
 			
844 844
 			$member->FirstName = $permCode;
845 845
 			$member->Surname = "User";
6  model/DataList.php
@@ -454,9 +454,9 @@ protected function createDataObject($row) {
454 454
 		
455 455
 		// Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass
456 456
 		if(class_exists($row['RecordClassName'])) {
457  
-			$item = new $row['RecordClassName']($row, false, $this->model);
  457
+			$item = Injector::inst()->create($row['RecordClassName'], $row, false, $this->model);
458 458
 		} else {
459  
-			$item = new $defaultClass($row, false, $this->model);
  459
+			$item = Injector::inst()->create($defaultClass, $row, false, $this->model);
460 460
 		}
461 461
 		
462 462
 		return $item;
@@ -765,7 +765,7 @@ public function add($item) {
765 765
 	 */
766 766
 	public function newObject($initialFields = null) {
767 767
 		$class = $this->dataClass;
768  
- 		return new $class($initialFields, false, $this->model);
  768
+ 		return Injector::inst()->create($class, $initialFields, false, $this->model);
769 769
 	}
770 770
 	
771 771
 	/**
2  model/DataObject.php
@@ -1447,7 +1447,7 @@ public function setComponent($componentName, $componentValue) {
1447 1447
 	public function getManyManyComponents($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
1448 1448
 		list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName);
1449 1449
 		
1450  
-		$result = new ManyManyList($componentClass, $table, $componentField, $parentField,
  1450
+		$result = Injector::inst()->create('ManyManyList', $componentClass, $table, $componentField, $parentField,
1451 1451
 			$this->many_many_extraFields($componentName));
1452 1452
 		if($this->model) $result->setDataModel($this->model);
1453 1453
 
2  security/Member.php
@@ -934,7 +934,7 @@ public function getTimeFormat() {
934 934
 	 * @todo Push all this logic into Member_GroupSet's getIterator()?
935 935
 	 */
936 936
 	public function Groups() {
937  
-		$groups = new Member_GroupSet('Group', 'Group_Members', 'GroupID', 'MemberID');
  937
+		$groups = Injector::inst()->create('Member_GroupSet', 'Group', 'Group_Members', 'GroupID', 'MemberID');
938 938
 		$groups->setForeignID($this->ID);
939 939
 		
940 940
 		$this->extend('updateGroups', $groups);

0 notes on commit 82a1e7d

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