ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SAML2\Utilities\ArrayCollection Class Reference

Simple Array implementation of Collection. More...

+ Inheritance diagram for SAML2\Utilities\ArrayCollection:
+ Collaboration diagram for SAML2\Utilities\ArrayCollection:

Public Member Functions

 __construct (array $elements=array())
 
 add ($element)
 Add an element to the collection. More...
 
 get ($key)
 Get the element at index. More...
 
 filter (\Closure $f)
 
 set ($key, $value)
 Set the value for index. More...
 
 remove ($element)
 
 getOnlyElement ()
 Shorthand for getting a single element that also must be the only element in the collection. More...
 
 first ()
 Return the first element from the collection. More...
 
 last ()
 Return the last element from the collection. More...
 
 map (\Closure $function)
 Applies the given function to each element in the collection and returns a new collection with the elements returned by the function. More...
 
 count ()
 
 getIterator ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 

Protected Attributes

 $elements
 

Detailed Description

Simple Array implementation of Collection.

(PHPMD.TooManyMethods) - it just has a large api.

Definition at line 12 of file ArrayCollection.php.

Constructor & Destructor Documentation

◆ __construct()

SAML2\Utilities\ArrayCollection::__construct ( array  $elements = array())

Definition at line 19 of file ArrayCollection.php.

References SAML2\Utilities\ArrayCollection\$elements.

20  {
21  $this->elements = $elements;
22  }

Member Function Documentation

◆ add()

SAML2\Utilities\ArrayCollection::add (   $element)

Add an element to the collection.

Parameters
$element
Returns
$this|

Implements SAML2\Utilities\Collection.

Definition at line 24 of file ArrayCollection.php.

25  {
26  $this->elements[] = $element;
27  }

◆ count()

SAML2\Utilities\ArrayCollection::count ( )

Definition at line 86 of file ArrayCollection.php.

Referenced by SAML2\Utilities\ArrayCollection\getOnlyElement().

87  {
88  return count($this->elements);
89  }
+ Here is the caller graph for this function:

◆ filter()

SAML2\Utilities\ArrayCollection::filter ( \Closure  $filterFunction)
Parameters
callable$filterFunction
Returns

Implements SAML2\Utilities\Collection.

Definition at line 34 of file ArrayCollection.php.

35  {
36  return new self(array_filter($this->elements, $f));
37  }

◆ first()

SAML2\Utilities\ArrayCollection::first ( )

Return the first element from the collection.

Returns
mixed

Implements SAML2\Utilities\Collection.

Definition at line 71 of file ArrayCollection.php.

72  {
73  return reset($this->elements);
74  }

◆ get()

SAML2\Utilities\ArrayCollection::get (   $key)

Get the element at index.

Parameters
mixed$key
Returns
mixed

Implements SAML2\Utilities\Collection.

Definition at line 29 of file ArrayCollection.php.

References $key.

30  {
31  return isset($this->elements[$key]) ? $this->elements[$key] : null;
32  }
$key
Definition: croninfo.php:18

◆ getIterator()

SAML2\Utilities\ArrayCollection::getIterator ( )

Definition at line 91 of file ArrayCollection.php.

92  {
93  return new \ArrayIterator($this->elements);
94  }

◆ getOnlyElement()

SAML2\Utilities\ArrayCollection::getOnlyElement ( )

Shorthand for getting a single element that also must be the only element in the collection.

Returns
mixed
Exceptions

Implements SAML2\Utilities\Collection.

Definition at line 58 of file ArrayCollection.php.

References SAML2\Utilities\ArrayCollection\count().

59  {
60  if ($this->count() !== 1) {
61  throw new RuntimeException(sprintf(
62  __CLASS__ . '::' . __METHOD__ . ' requires that the collection has exactly one element, '
63  . '"%d" elements found',
64  $this->count()
65  ));
66  }
67 
68  return reset($this->elements);
69  }
+ Here is the call graph for this function:

◆ last()

SAML2\Utilities\ArrayCollection::last ( )

Return the last element from the collection.

Returns
mixed

Implements SAML2\Utilities\Collection.

Definition at line 76 of file ArrayCollection.php.

77  {
78  return end($this->elements);
79  }

◆ map()

SAML2\Utilities\ArrayCollection::map ( \Closure  $function)

Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.

Parameters
callable$function
Returns
mixed

Implements SAML2\Utilities\Collection.

Definition at line 81 of file ArrayCollection.php.

82  {
83  return new self(array_map($function, $this->elements));
84  }

◆ offsetExists()

SAML2\Utilities\ArrayCollection::offsetExists (   $offset)

Definition at line 96 of file ArrayCollection.php.

97  {
98  return isset($this->elements[$offset]);
99  }

◆ offsetGet()

SAML2\Utilities\ArrayCollection::offsetGet (   $offset)

Definition at line 101 of file ArrayCollection.php.

102  {
103  return $this->elements[$offset];
104  }

◆ offsetSet()

SAML2\Utilities\ArrayCollection::offsetSet (   $offset,
  $value 
)

Definition at line 106 of file ArrayCollection.php.

107  {
108  $this->elements[$offset] = $value;
109  }

◆ offsetUnset()

SAML2\Utilities\ArrayCollection::offsetUnset (   $offset)

Definition at line 111 of file ArrayCollection.php.

112  {
113  unset($this->elements[$offset]);
114  }

◆ remove()

SAML2\Utilities\ArrayCollection::remove (   $element)
Parameters
$element

Implements SAML2\Utilities\Collection.

Definition at line 44 of file ArrayCollection.php.

References $key.

45  {
46  $key = array_search($element, $this->elements);
47 
48  if ($key === false) {
49  return false;
50  }
51 
52  $removed = $this->elements[$key];
53  unset($this->elements[$key]);
54 
55  return $removed;
56  }
$key
Definition: croninfo.php:18

◆ set()

SAML2\Utilities\ArrayCollection::set (   $key,
  $value 
)

Set the value for index.

Parameters
mixed$key
mixed$value

Implements SAML2\Utilities\Collection.

Definition at line 39 of file ArrayCollection.php.

References $key.

40  {
41  $this->elements[$key] = $value;
42  }
$key
Definition: croninfo.php:18

Field Documentation

◆ $elements

SAML2\Utilities\ArrayCollection::$elements
protected

Definition at line 17 of file ArrayCollection.php.

Referenced by SAML2\Utilities\ArrayCollection\__construct().


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