mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Prep ArrayList for immutability in 3.1 per 7673
ArrayList had several methods that should act on a copy and return that copy, but was instead mutating the existing list. We cant change this behaviour in the 3.0 line for backwards compt. reasons, but this makes the desired behavior the default, and makes disabling the mutation in 3.1 easier
This commit is contained in:
parent
c9b3430470
commit
1ed41b8d67
@ -300,9 +300,11 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function reverse() {
|
||||
$this->items = array_reverse($this->items);
|
||||
// TODO 3.1: This currently mutates existing array
|
||||
$list = /* clone */ $this;
|
||||
$list->items = array_reverse($this->items);
|
||||
|
||||
return $this;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,11 +364,13 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
||||
// First argument is the direction to be sorted,
|
||||
$multisortArgs[] = &$sortDirection[$column];
|
||||
}
|
||||
// As the last argument we pass in a reference to the items that all the sorting will be
|
||||
// applied upon
|
||||
$multisortArgs[] = &$this->items;
|
||||
|
||||
// TODO 3.1: This currently mutates existing array
|
||||
$list = /* clone */ $this;
|
||||
// As the last argument we pass in a reference to the items that all the sorting will be applied upon
|
||||
$multisortArgs[] = &$list->items;
|
||||
call_user_func_array('array_multisort', $multisortArgs);
|
||||
return $this;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -424,8 +428,10 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
||||
}
|
||||
}
|
||||
|
||||
$this->items = $itemsToKeep;
|
||||
return $this;
|
||||
// TODO 3.1: This currently mutates existing array
|
||||
$list = /* clone */ $this;
|
||||
$list->items = $itemsToKeep;
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function byID($id) {
|
||||
@ -478,12 +484,14 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
||||
}
|
||||
|
||||
$keysToRemove = array_keys($matches,$hitsRequiredToRemove);
|
||||
// TODO 3.1: This currently mutates existing array
|
||||
$list = /* clone */ $this;
|
||||
|
||||
foreach($keysToRemove as $itemToRemoveIdx){
|
||||
$this->remove($this->items[$itemToRemoveIdx]);
|
||||
$list->remove($this->items[$itemToRemoveIdx]);
|
||||
}
|
||||
return;
|
||||
|
||||
return $this;
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function shouldExclude($item, $args) {
|
||||
|
Loading…
Reference in New Issue
Block a user