Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
Marcus Nyeholt authored
2  core/Core.php
View
@@ -283,7 +283,7 @@
// initialise the dependency injector
$default_options = array('locator' => 'SilverStripeServiceConfigurationLocator');
-Injector::inst($default_options)->addAutoProperty('injector', Injector::inst());
+Injector::inst($default_options);
///////////////////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS
6 dev/SapphireTest.php
View
@@ -829,17 +829,17 @@ function resetDBSchema($includeExtraDataObjects = false) {
*/
function logInWithPermission($permCode = "ADMIN") {
if(!isset($this->cache_generatedMembers[$permCode])) {
- $group = new Group();
+ $group = Injector::inst()->create('Group');
$group->Title = "$permCode group";
$group->write();
- $permission = new Permission();
+ $permission = Injector::inst()->create('Permission');
$permission->Code = $permCode;
$permission->write();
$group->Permissions()->add($permission);
$member = DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "$permCode@example.org"));
- if(!$member) $member = new Member();
+ if(!$member) $member = Injector::inst()->create('Member');
$member->FirstName = $permCode;
$member->Surname = "User";
6 model/DataList.php
View
@@ -454,9 +454,9 @@ protected function createDataObject($row) {
// Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass
if(class_exists($row['RecordClassName'])) {
- $item = new $row['RecordClassName']($row, false, $this->model);
+ $item = Injector::inst()->create($row['RecordClassName'], $row, false, $this->model);
} else {
- $item = new $defaultClass($row, false, $this->model);
+ $item = Injector::inst()->create($defaultClass, $row, false, $this->model);
}
return $item;
@@ -765,7 +765,7 @@ public function add($item) {
*/
public function newObject($initialFields = null) {
$class = $this->dataClass;
- return new $class($initialFields, false, $this->model);
+ return Injector::inst()->create($class, $initialFields, false, $this->model);
}
/**
2  model/DataObject.php
View
@@ -1447,7 +1447,7 @@ public function setComponent($componentName, $componentValue) {
public function getManyManyComponents($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName);
- $result = new ManyManyList($componentClass, $table, $componentField, $parentField,
+ $result = Injector::inst()->create('ManyManyList', $componentClass, $table, $componentField, $parentField,
$this->many_many_extraFields($componentName));
if($this->model) $result->setDataModel($this->model);
2  security/Member.php
View
@@ -934,7 +934,7 @@ public function getTimeFormat() {
* @todo Push all this logic into Member_GroupSet's getIterator()?
*/
public function Groups() {
- $groups = new Member_GroupSet('Group', 'Group_Members', 'GroupID', 'MemberID');
+ $groups = Injector::inst()->create('Member_GroupSet', 'Group', 'Group_Members', 'GroupID', 'MemberID');
$groups->setForeignID($this->ID);
$this->extend('updateGroups', $groups);
Please sign in to comment.
Something went wrong with that request. Please try again.