silverstripe-framework/src/ORM/SS_List.php

94 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\ORM;
use ArrayAccess;
use Countable;
use IteratorAggregate;
/**
* An interface that a class can implement to be treated as a list container.
*/
2016-11-29 00:31:16 +01:00
interface SS_List extends ArrayAccess, Countable, IteratorAggregate
{
2016-11-29 00:31:16 +01:00
/**
* Returns all the items in the list in an array.
*
* @return array
*/
public function toArray();
2016-11-29 00:31:16 +01:00
/**
* Returns the contents of the list as an array of maps.
*
* @return array
*/
public function toNestedArray();
2016-11-29 00:31:16 +01:00
/**
* Adds an item to the list, making no guarantees about where it will
* appear.
*
* @param mixed $item
*/
public function add($item);
2016-11-29 00:31:16 +01:00
/**
* Removes an item from the list.
*
* @param mixed $item
*/
public function remove($item);
2016-11-29 00:31:16 +01:00
/**
* Returns the first item in the list.
*
* @return mixed
*/
public function first();
2016-11-29 00:31:16 +01:00
/**
* Returns the last item in the list.
*
* @return mixed
*/
public function last();
2016-11-29 00:31:16 +01:00
/**
* Returns a map of a key field to a value field of all the items in the
* list.
*
* @param string $keyfield
* @param string $titlefield
* @return Map
*/
public function map($keyfield = 'ID', $titlefield = 'Title');
2016-11-29 00:31:16 +01:00
/**
* Returns the first item in the list where the key field is equal to the
* value.
*
* @param string $key
* @param mixed $value
* @return mixed
*/
public function find($key, $value);
2016-11-29 00:31:16 +01:00
/**
* Returns an array of a single field value for all items in the list.
*
* @param string $colName
* @return array
*/
public function column($colName = "ID");
2014-08-15 08:53:05 +02:00
2016-11-29 00:31:16 +01:00
/**
* Walks the list using the specified callback
*
* @param callable $callback
* @return $this
*/
public function each($callback);
}