Compare commits

..

2 Commits

Author SHA1 Message Date
Steve Boyd
595656636c
Merge 3ce511ca50 into ba97de9458 2024-10-21 04:53:08 +00:00
Steve Boyd
3ce511ca50 API Combine Sortable, Filterable and Limitable into SS_List 2024-10-21 17:53:02 +13:00
5 changed files with 20 additions and 24 deletions

View File

@ -851,7 +851,7 @@ class ArrayList extends ModelData implements SS_List
}
/**
* @see SS_List::filterByCallback()
* @see Filterable::filterByCallback()
*
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
* @param callable $callback
@ -861,7 +861,7 @@ class ArrayList extends ModelData implements SS_List
{
if (!is_callable($callback)) {
throw new LogicException(sprintf(
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
gettype($callback)
));
}

View File

@ -11,18 +11,19 @@ use Traversable;
* functionality. It passes through list methods to the underlying list
* implementation.
*
* @template TList of SS_List
* @template T
* @implements SS_List<T>
*/
abstract class ListDecorator extends ModelData implements SS_List
{
/**
* @var SS_List<T>
* @var TList<T>
*/
protected SS_List $list;
protected SS_List&Sortable&Filterable&Limitable $list;
/**
* @param SS_List<T> $list
* @param TList<T> $list
*/
public function __construct(SS_List $list)
{
@ -31,7 +32,7 @@ abstract class ListDecorator extends ModelData implements SS_List
}
/**
* @return SS_List<T>
* @return TList<T>
*/
public function getList(): SS_List
{
@ -44,10 +45,10 @@ abstract class ListDecorator extends ModelData implements SS_List
* Useful for keeping a decorator/paginated list configuration intact while modifying
* the underlying list.
*
* @template SS_ListA
* @template TListA
* @template TA
* @param SS_ListA<TA> $list
* @return static<SS_ListA, TA>
* @param TListA<TA> $list
* @return static<TListA, TA>
*/
public function setList(SS_List $list): ListDecorator
{
@ -161,7 +162,7 @@ abstract class ListDecorator extends ModelData implements SS_List
}
/**
* @return SS_List<T>
* @return TList<T>
*/
public function each($callback)
{
@ -187,7 +188,7 @@ abstract class ListDecorator extends ModelData implements SS_List
* @example $list->sort('Name', 'ASC');
* @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
*
* @return SS_List<T>
* @return TList<T>
*/
public function sort()
{
@ -207,7 +208,7 @@ abstract class ListDecorator extends ModelData implements SS_List
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob or someone with Age 21
* @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob or anyone with Age 21 or 43
*
* @return SS_List<T>
* @return TList<T>
*/
public function filter()
{
@ -235,7 +236,7 @@ abstract class ListDecorator extends ModelData implements SS_List
*
* @param string|array See {@link filter()}
*
* @return SS_List<T>
* @return TList<T>
*/
public function filterAny()
{
@ -255,7 +256,7 @@ abstract class ListDecorator extends ModelData implements SS_List
{
if (!is_callable($callback)) {
throw new LogicException(sprintf(
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
gettype($callback)
));
}
@ -269,7 +270,7 @@ abstract class ListDecorator extends ModelData implements SS_List
}
/**
* @return SS_List<T>
* @return TList<T>
*/
public function limit(?int $length, int $offset = 0): SS_List
{
@ -286,7 +287,7 @@ abstract class ListDecorator extends ModelData implements SS_List
*
* @param array $ids Array of integers
*
* @return SS_List<T>
* @return TList<T>
*/
public function byIDs($ids)
{
@ -301,7 +302,7 @@ abstract class ListDecorator extends ModelData implements SS_List
* @example $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob or someone with Age 21
* @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob or anyone with Age 21 or 43
*
* @return SS_List<T>
* @return TList<T>
*/
public function exclude()
{

View File

@ -15,11 +15,6 @@ use IteratorAggregate;
*/
interface SS_List extends ArrayAccess, Countable, IteratorAggregate
{
/**
* Representation of the list for use in a template
*/
public function forTemplate(): string;
/**
* Returns all the items in the list in an array.
*

View File

@ -595,7 +595,7 @@ class DataList extends ModelData implements SS_List
{
if (!is_callable($callback)) {
throw new LogicException(sprintf(
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
gettype($callback)
));
}

View File

@ -1455,7 +1455,7 @@ class ArrayListTest extends SapphireTest
$this->assertEquals(2, $list->count());
$this->assertEquals($steve, $list[0]->toMap(), 'List should only contain Steve and Clair');
$this->assertEquals($clair, $list[1]->toMap(), 'List should only contain Steve and Clair');
$this->assertTrue($list instanceof SS_List, 'The List should be of type SS_List');
$this->assertTrue($list instanceof SS_List, 'The List should be of type SS_Filterable');
}
/**