ILIAS  release_8 Revision v8.24
ilBuddySystemArrayCollection Class Reference

Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list. More...

+ Inheritance diagram for ilBuddySystemArrayCollection:
+ Collaboration diagram for ilBuddySystemArrayCollection:

Public Member Functions

 __construct (array $elements=[])
 
 getIterator ()
 @inheritDoc More...
 
 offsetExists ($offset)
 @inheritDoc More...
 
 offsetGet ($offset)
 @inheritDoc More...
 
 offsetSet ($offset, $value)
 @inheritDoc More...
 
 offsetUnset ($offset)
 @inheritDoc More...
 
 count ()
 @inheritDoc More...
 
 add ($element)
 @inheritDoc More...
 
 remove ($key)
 @inheritDoc More...
 
 removeElement ($element)
 @inheritDoc More...
 
 containsKey ($key)
 isset is used for performance reasons (array_key_exists is much slower). More...
 
 getKey ($element)
 @inheritDoc More...
 
 clear ()
 @inheritDoc More...
 
 contains ($element)
 @inheritDoc More...
 
 get ($key)
 @inheritDoc More...
 
 set ($key, $value)
 @inheritDoc More...
 
 isEmpty ()
 @inheritDoc More...
 
 getKeys ()
 @inheritDoc More...
 
 getValues ()
 @inheritDoc More...
 
 filter (callable $callable)
 @inheritDoc More...
 
 slice (int $offset, int $length=null)
 @inheritDoc More...
 
 toArray ()
 @inheritDoc More...
 
 equals ($other)
 
 add ($element)
 Adds an element at the end of the collection. More...
 
 remove ($key)
 
 removeElement ($element)
 
 containsKey ($key)
 
 getKey ($element)
 
 clear ()
 Clears the list. More...
 
 contains ($element)
 
 get ($key)
 
 set ($key, $value)
 
 isEmpty ()
 
 getKeys ()
 Gets all indices of the collection. More...
 
 getValues ()
 Gets all values of the collection. More...
 
 filter (callable $callable)
 Returns all the elements of this collection that satisfy the predicate $callable. More...
 
 slice (int $offset, int $length=null)
 Extracts a slice of $length elements starting at position $offset from the Collection. More...
 
 toArray ()
 
 equals ($other)
 

Private Attributes

array $elements
 

Detailed Description

Class ilBuddySystemArrayCollection A collection which contains all entries of a buddy list.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 26 of file class.ilBuddySystemArrayCollection.php.

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemArrayCollection::__construct ( array  $elements = [])

Definition at line 30 of file class.ilBuddySystemArrayCollection.php.

31 {
32 $this->elements = $elements;
33 }

References $elements.

Member Function Documentation

◆ add()

ilBuddySystemArrayCollection::add (   $element)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 92 of file class.ilBuddySystemArrayCollection.php.

92 : void
93 {
94 $this->elements[] = $element;
95 }

Referenced by offsetSet().

+ Here is the caller graph for this function:

◆ clear()

ilBuddySystemArrayCollection::clear ( )

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 142 of file class.ilBuddySystemArrayCollection.php.

142 : void
143 {
144 $this->elements = [];
145 }

◆ contains()

ilBuddySystemArrayCollection::contains (   $element)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 150 of file class.ilBuddySystemArrayCollection.php.

150 : bool
151 {
152 return in_array($element, $this->elements, true);
153 }

◆ containsKey()

ilBuddySystemArrayCollection::containsKey (   $key)

isset is used for performance reasons (array_key_exists is much slower).

array_key_exists is only used in case of a null value (see https://www.php.net/manual/en/function.array-key-exists.php Example #2 array_key_exists() vs isset()).

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 126 of file class.ilBuddySystemArrayCollection.php.

126 : bool
127 {
128 return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
129 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

Referenced by offsetExists(), and remove().

+ Here is the caller graph for this function:

◆ count()

ilBuddySystemArrayCollection::count ( )

@inheritDoc

Definition at line 84 of file class.ilBuddySystemArrayCollection.php.

84 : int
85 {
86 return count($this->elements);
87 }

References count().

Referenced by count().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ equals()

ilBuddySystemArrayCollection::equals (   $other)
Parameters
mixed$other
Returns
bool

Implements ilBuddySystemCollection.

Definition at line 219 of file class.ilBuddySystemArrayCollection.php.

219 : bool
220 {
221 if (!($other instanceof self)) {
222 return false;
223 }
224
225 $self = $this->toArray();
226 $other = $other->toArray();
227
228 sort($self);
229 sort($other);
230
231 return $self == $other;
232 }

References toArray().

+ Here is the call graph for this function:

◆ filter()

ilBuddySystemArrayCollection::filter ( callable  $callable)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 198 of file class.ilBuddySystemArrayCollection.php.

199 {
200 return new static(array_filter($this->elements, $callable));
201 }
Interface ilBuddySystemCollection.

Referenced by ilBuddySystemRelationStateFilterRule\getStates().

+ Here is the caller graph for this function:

◆ get()

ilBuddySystemArrayCollection::get (   $key)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 158 of file class.ilBuddySystemArrayCollection.php.

159 {
160 return $this->elements[$key] ?? null;
161 }

References ILIAS\LTI\ToolProvider\$key.

◆ getIterator()

ilBuddySystemArrayCollection::getIterator ( )

@inheritDoc

Definition at line 38 of file class.ilBuddySystemArrayCollection.php.

39 {
40 return new ArrayIterator($this->elements);
41 }

◆ getKey()

ilBuddySystemArrayCollection::getKey (   $element)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 134 of file class.ilBuddySystemArrayCollection.php.

135 {
136 return array_search($element, $this->elements, true);
137 }

◆ getKeys()

ilBuddySystemArrayCollection::getKeys ( )

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 182 of file class.ilBuddySystemArrayCollection.php.

182 : array
183 {
184 return array_keys($this->elements);
185 }

◆ getValues()

ilBuddySystemArrayCollection::getValues ( )

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 190 of file class.ilBuddySystemArrayCollection.php.

190 : array
191 {
192 return array_values($this->elements);
193 }

◆ isEmpty()

ilBuddySystemArrayCollection::isEmpty ( )

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 174 of file class.ilBuddySystemArrayCollection.php.

174 : bool
175 {
176 return empty($this->elements);
177 }

◆ offsetExists()

ilBuddySystemArrayCollection::offsetExists (   $offset)

@inheritDoc

Definition at line 46 of file class.ilBuddySystemArrayCollection.php.

46 : bool
47 {
48 return $this->containsKey($offset);
49 }
containsKey($key)
isset is used for performance reasons (array_key_exists is much slower).

References containsKey().

+ Here is the call graph for this function:

◆ offsetGet()

ilBuddySystemArrayCollection::offsetGet (   $offset)

@inheritDoc

Definition at line 54 of file class.ilBuddySystemArrayCollection.php.

55 {
56 return $this->get($offset);
57 }

◆ offsetSet()

ilBuddySystemArrayCollection::offsetSet (   $offset,
  $value 
)

@inheritDoc

Definition at line 62 of file class.ilBuddySystemArrayCollection.php.

62 : void
63 {
64 if (!isset($offset)) {
65 $this->add($value);
66
67 return;
68 }
69
70 $this->set($offset, $value);
71 }

References add().

+ Here is the call graph for this function:

◆ offsetUnset()

ilBuddySystemArrayCollection::offsetUnset (   $offset)

@inheritDoc

Definition at line 76 of file class.ilBuddySystemArrayCollection.php.

76 : void
77 {
78 $this->remove($offset);
79 }

◆ remove()

ilBuddySystemArrayCollection::remove (   $key)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 100 of file class.ilBuddySystemArrayCollection.php.

100 : void
101 {
102 if (!$this->containsKey($key)) {
103 throw new InvalidArgumentException(sprintf('Could not find an element for key: %s', $key));
104 }
105 unset($this->elements[$key]);
106 }

References ILIAS\LTI\ToolProvider\$key, and containsKey().

+ Here is the call graph for this function:

◆ removeElement()

ilBuddySystemArrayCollection::removeElement (   $element)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 111 of file class.ilBuddySystemArrayCollection.php.

111 : void
112 {
113 $key = array_search($element, $this->elements, true);
114 if (false === $key) {
115 throw new InvalidArgumentException('Could not find an key for the passed element.');
116 }
117 unset($this->elements[$key]);
118 }

References ILIAS\LTI\ToolProvider\$key.

◆ set()

ilBuddySystemArrayCollection::set (   $key,
  $value 
)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 166 of file class.ilBuddySystemArrayCollection.php.

166 : void
167 {
168 $this->elements[$key] = $value;
169 }

References ILIAS\LTI\ToolProvider\$key.

◆ slice()

ilBuddySystemArrayCollection::slice ( int  $offset,
int  $length = null 
)

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 206 of file class.ilBuddySystemArrayCollection.php.

207 {
208 return new static(array_slice($this->elements, $offset, $length, true));
209 }

◆ toArray()

ilBuddySystemArrayCollection::toArray ( )

@inheritDoc

Implements ilBuddySystemCollection.

Definition at line 214 of file class.ilBuddySystemArrayCollection.php.

214 : array
215 {
216 return $this->elements;
217 }

References $elements.

Referenced by equals().

+ Here is the caller graph for this function:

Field Documentation

◆ $elements

array ilBuddySystemArrayCollection::$elements
private

Definition at line 28 of file class.ilBuddySystemArrayCollection.php.

Referenced by __construct(), and toArray().


The documentation for this class was generated from the following file: