ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBuddySystemArrayCollection.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Contact/BuddySystem/interfaces/interface.ilBuddySystemCollection.php';
5 
12 {
16  private $elements = array();
17 
21  public function __construct(array $elements = array())
22  {
23  $this->elements = $elements;
24  }
25 
29  public function getIterator()
30  {
31  return new ArrayIterator($this->elements);
32  }
33 
37  public function offsetExists($offset)
38  {
39  return $this->containsKey($offset);
40  }
41 
45  public function offsetGet($offset)
46  {
47  return $this->get($offset);
48  }
49 
53  public function offsetSet($offset, $value)
54  {
55  if (!isset($offset)) {
56  $this->add($value);
57  return;
58  }
59 
60  $this->set($offset, $value);
61  }
62 
66  public function offsetUnset($offset)
67  {
68  $this->remove($offset);
69  }
70 
74  public function count()
75  {
76  return count($this->elements);
77  }
78 
82  public function add($element)
83  {
84  $this->elements[] = $element;
85  }
86 
90  public function remove($key)
91  {
92  if (!isset($this->elements[$key]) && !array_key_exists($key, $this->elements)) {
93  throw new InvalidArgumentException(sprintf("Could not find an element for key: ", $key));
94  }
95  unset($this->elements[$key]);
96  }
97 
101  public function removeElement($element)
102  {
103  $key = array_search($element, $this->elements, true);
104  if (false === $key) {
105  throw new InvalidArgumentException("Could not find an key for the passed element.");
106  }
107  unset($this->elements[$key]);
108  }
109 
113  public function containsKey($key)
114  {
115  return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
116  }
117 
122  public function getKey($element)
123  {
124  return array_search($element, $this->elements, true);
125  }
126 
130  public function clear()
131  {
132  $this->elements = array();
133  }
134 
138  public function contains($element)
139  {
140  return in_array($element, $this->elements, true);
141  }
142 
146  public function get($key)
147  {
148  return isset($this->elements[$key]) ? $this->elements[$key] : null;
149  }
150 
154  public function set($key, $value)
155  {
156  $this->elements[$key] = $value;
157  }
158 
162  public function isEmpty()
163  {
164  return empty($this->elements);
165  }
166 
170  public function getKeys()
171  {
172  return array_keys($this->elements);
173  }
174 
178  public function getValues()
179  {
180  return array_values($this->elements);
181  }
182 
186  public function filter(Closure $p)
187  {
188  return new static(array_filter($this->elements, $p));
189  }
190 
194  public function slice($offset, $length = null)
195  {
196  return new static(array_slice($this->elements, $offset, $length, true));
197  }
198 
202  public function toArray()
203  {
204  return $this->elements;
205  }
206 }
add($element)
Adds an element at the end of the collection.
getValues()
Gets all values of the collection.array The values of all elements in the collection, in the order they appear in the collection.
isEmpty()
boolean true if the collection is empty, false otherwise.
Interface ilBuddySystemCollection.
Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list...
filter(Closure $p)
Returns all the elements of this collection that satisfy the predicate $callable.ilBuddySystemCollect...
slice($offset, $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection.If $length is null it returns all elements from $offset to the end of the Collection. Calling this method will only return the selected slice and NOT change the elements contained in the collection slice is called on. The offset to start from. The maximum number of elements to return, or null for no limit. ilBuddySystemCollection
containsKey($key)
The index to check for. boolean true if the collection contains the element, false otherwise...
contains($element)
boolean true if the collection contains the element, false otherwise.
getKeys()
Gets all indices of the collection.array The indices of the collection, in the order of the correspon...
removeElement($element)
The element to remove.
$key
Definition: croninfo.php:18