ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_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}
Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list.
contains($element)
boolean true if the collection contains the element, false otherwise.
containsKey($key)
boolean true if the collection contains the element, false otherwise.
slice($offset, $length=null)
Extracts a slice of $length elements starting at position $offset from the Collection....
isEmpty()
boolean true if the collection is empty, false otherwise.
filter(Closure $p)
Returns all the elements of this collection that satisfy the predicate $callable.ilBuddySystemCollect...
getKeys()
Gets all indices of the collection.array The indices of the collection, in the order of the correspon...
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,...
Interface ilBuddySystemCollection.