ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Slim\Collection Class Reference

Collection. More...

+ Inheritance diagram for Slim\Collection:
+ Collaboration diagram for Slim\Collection:

Public Member Functions

 __construct (array $items=[])
 Create new collection. More...
 
 set ($key, $value)
 Set collection item. More...
 
 get ($key, $default=null)
 Get collection item for key. More...
 
 replace (array $items)
 Add item to collection, replacing existing items with the same data key. More...
 
 all ()
 Get all items in collection. More...
 
 keys ()
 Get collection keys. More...
 
 has ($key)
 Does this collection have a given key? More...
 
 remove ($key)
 Remove item from collection. More...
 
 clear ()
 Remove all items from collection. More...
 
 offsetExists ($key)
 Does this collection have a given key? More...
 
 offsetGet ($key)
 Get collection item for key. More...
 
 offsetSet ($key, $value)
 Set collection item. More...
 
 offsetUnset ($key)
 Remove item from collection. More...
 
 count ()
 Get number of items in collection. More...
 
 getIterator ()
 Get collection iterator. More...
 
 set ($key, $value)
 
 get ($key, $default=null)
 
 replace (array $items)
 
 all ()
 
 has ($key)
 
 remove ($key)
 
 clear ()
 

Protected Attributes

 $data = []
 

Detailed Description

Collection.

This class provides a common interface used by many other classes in a Slim application that manage "collections" of data that must be inspected and/or manipulated

Definition at line 21 of file Collection.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\Collection::__construct ( array  $items = [])

Create new collection.

Parameters
array$itemsPre-populate collection with this key-value array

Definition at line 35 of file Collection.php.

36 {
37 $this->replace($items);
38 }
replace(array $items)
Add item to collection, replacing existing items with the same data key.
Definition: Collection.php:73

Member Function Documentation

◆ all()

Slim\Collection::all ( )

Get all items in collection.

Returns
array The collection's source data

Implements Slim\Interfaces\CollectionInterface.

Reimplemented in Slim\Http\Headers.

Definition at line 85 of file Collection.php.

86 {
87 return $this->data;
88 }

References $data.

Referenced by Slim\Http\Request\createFromEnvironment().

+ Here is the caller graph for this function:

◆ clear()

Slim\Collection::clear ( )

Remove all items from collection.

Implements Slim\Interfaces\CollectionInterface.

Definition at line 125 of file Collection.php.

126 {
127 $this->data = [];
128 }
$this data['403_header']

References data.

◆ count()

Slim\Collection::count ( )

Get number of items in collection.

Returns
int

Definition at line 184 of file Collection.php.

185 {
186 return count($this->data);
187 }
count()
Get number of items in collection.
Definition: Collection.php:184

References data.

◆ get()

Slim\Collection::get (   $key,
  $default = null 
)

Get collection item for key.

Parameters
string$keyThe data key
mixed$defaultThe default value to return if data key does not exist
Returns
mixed The key's value, or the default value

Implements Slim\Interfaces\CollectionInterface.

Reimplemented in Slim\Http\Headers.

Definition at line 63 of file Collection.php.

64 {
65 return $this->has($key) ? $this->data[$key] : $default;
66 }
has($key)
Does this collection have a given key?
Definition: Collection.php:107
$key
Definition: croninfo.php:18

References $key, and data.

Referenced by Slim\Http\Headers\determineAuthorization().

+ Here is the caller graph for this function:

◆ getIterator()

Slim\Collection::getIterator ( )

Get collection iterator.

Returns
\ArrayIterator

Definition at line 198 of file Collection.php.

199 {
200 return new ArrayIterator($this->data);
201 }

References data.

◆ has()

Slim\Collection::has (   $key)

Does this collection have a given key?

Parameters
string$keyThe data key
Returns
bool

Implements Slim\Interfaces\CollectionInterface.

Reimplemented in Slim\Http\Headers.

Definition at line 107 of file Collection.php.

108 {
109 return array_key_exists($key, $this->data);
110 }

References $key, and data.

◆ keys()

Slim\Collection::keys ( )

Get collection keys.

Returns
array The collection's source data keys

Definition at line 95 of file Collection.php.

96 {
97 return array_keys($this->data);
98 }

References data.

◆ offsetExists()

Slim\Collection::offsetExists (   $key)

Does this collection have a given key?

Parameters
string$keyThe data key
Returns
bool

Definition at line 141 of file Collection.php.

142 {
143 return $this->has($key);
144 }

References $key.

◆ offsetGet()

Slim\Collection::offsetGet (   $key)

Get collection item for key.

Parameters
string$keyThe data key
Returns
mixed The key's value, or the default value

Definition at line 153 of file Collection.php.

154 {
155 return $this->get($key);
156 }

References $key.

◆ offsetSet()

Slim\Collection::offsetSet (   $key,
  $value 
)

Set collection item.

Parameters
string$keyThe data key
mixed$valueThe data value

Definition at line 164 of file Collection.php.

165 {
166 $this->set($key, $value);
167 }

References $key.

◆ offsetUnset()

Slim\Collection::offsetUnset (   $key)

Remove item from collection.

Parameters
string$keyThe data key

Definition at line 174 of file Collection.php.

175 {
176 $this->remove($key);
177 }

References $key.

◆ remove()

Slim\Collection::remove (   $key)

Remove item from collection.

Parameters
string$keyThe data key

Implements Slim\Interfaces\CollectionInterface.

Reimplemented in Slim\Http\Headers.

Definition at line 117 of file Collection.php.

118 {
119 unset($this->data[$key]);
120 }

References $key, and data.

◆ replace()

Slim\Collection::replace ( array  $items)

Add item to collection, replacing existing items with the same data key.

Parameters
array$itemsKey-value array of data to append to this collection

Implements Slim\Interfaces\CollectionInterface.

Definition at line 73 of file Collection.php.

74 {
75 foreach ($items as $key => $value) {
76 $this->set($key, $value);
77 }
78 }

References $key.

◆ set()

Slim\Collection::set (   $key,
  $value 
)

Set collection item.

Parameters
string$keyThe data key
mixed$valueThe data value

Implements Slim\Interfaces\CollectionInterface.

Reimplemented in Slim\Http\Headers.

Definition at line 50 of file Collection.php.

51 {
52 $this->data[$key] = $value;
53 }

References $key, and data.

Referenced by Slim\Http\Headers\determineAuthorization().

+ Here is the caller graph for this function:

Field Documentation

◆ $data

Slim\Collection::$data = []
protected

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