List.php
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
 * An interface that a class can implement to be treated as a list container.
 *
 * @package framework
 * @subpackage model
 */
interface SS_List extends ArrayAccess, Countable, IteratorAggregate {
	/**
	 * Returns all the items in the list in an array.
	 *
	 * @return arary
	 */
	public function toArray();
	/**
	 * Returns the contents of the list as an array of maps.
	 *
	 * @return array
	 */
	public function toNestedArray();
	/**
	 * Adds an item to the list, making no guarantees about where it will
	 * appear.
	 *
	 * @param mixed $item
	 */
	public function add($item);
	/**
	 * Removes an item from the list.
	 *
	 * @param mixed $item
	 */
	public function remove($item);
	/**
	 * Returns the first item in the list.
	 *
	 * @return mixed
	 */
	public function first();
	/**
	 * Returns the last item in the list.
	 *
	 * @return mixed
	 */
	public function last();
	/**
	 * 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 array
	 */
	public function map($keyfield = 'ID', $titlefield = 'Title');
	/**
	 * 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);
	/**
	 * Returns an array of a single field value for all items in the list.
	 *
	 * @param  string $colName
	 * @return array
	 */
	public function column($colName = "ID");
	
	/**
	 * Walks the list using the specified callback
	 *
	 * @param callable $callback
	 * @return mixed
	 */
	public function each($callback);
}