ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
57  $this->add($value);
58  return;
59  }
60 
61  $this->set($offset, $value);
62  }
63 
67  public function offsetUnset($offset)
68  {
69  $this->remove($offset);
70  }
71 
75  public function count()
76  {
77  return count($this->elements);
78  }
79 
83  public function add($element)
84  {
85  $this->elements[] = $element;
86  }
87 
91  public function remove($key)
92  {
93  if(!isset($this->elements[$key]) && !array_key_exists($key, $this->elements))
94  {
95  throw new InvalidArgumentException(sprintf("Could not find an element for key: ", $key));
96  }
97  unset($this->elements[$key]);
98  }
99 
103  public function removeElement($element)
104  {
105  $key = array_search($element, $this->elements, true);
106  if(false === $key)
107  {
108  throw new InvalidArgumentException("Could not find an key for the passed element.");
109  }
110  unset($this->elements[$key]);
111  }
112 
116  public function containsKey($key)
117  {
118  return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
119  }
120 
125  public function getKey($element)
126  {
127  return array_search($element, $this->elements, true);
128  }
129 
133  public function clear()
134  {
135  $this->elements = array();
136  }
137 
141  public function contains($element)
142  {
143  return in_array($element, $this->elements, true);
144  }
145 
149  public function get($key)
150  {
151  return isset($this->elements[$key]) ? $this->elements[$key] : null;
152  }
153 
157  public function set($key, $value)
158  {
159  $this->elements[$key] = $value;
160  }
161 
165  public function isEmpty()
166  {
167  return empty($this->elements);
168  }
169 
173  public function getKeys()
174  {
175  return array_keys($this->elements);
176  }
177 
181  public function getValues()
182  {
183  return array_values($this->elements);
184  }
185 
189  public function filter(Closure $p)
190  {
191  return new static(array_filter($this->elements, $p));
192  }
193 
197  public function slice($offset, $length = null)
198  {
199  return new static(array_slice($this->elements, $offset, $length, true));
200  }
201 
205  public function toArray()
206  {
207  return $this->elements;
208  }
209 }
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...
Create styles array
The data for the language used.
removeElement($element)
The element to remove.