ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 

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.

Definition at line 85 of file Collection.php.

References $data.

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

86  {
87  return $this->data;
88  }
+ 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.

References data.

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

◆ count()

Slim\Collection::count ( )

Get number of items in collection.

Returns
int

Definition at line 184 of file Collection.php.

References data.

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

◆ 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.

Definition at line 63 of file Collection.php.

References $default, $key, and data.

Referenced by Slim\Http\Uri\createFromEnvironment(), and Slim\Http\Headers\determineAuthorization().

64  {
65  return $this->has($key) ? $this->data[$key] : $default;
66  }
has($key)
Does this collection have a given key?
Definition: Collection.php:107
$default
Definition: build.php:20
$this data['403_header']
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getIterator()

Slim\Collection::getIterator ( )

Get collection iterator.

Returns

Definition at line 198 of file Collection.php.

References data.

199  {
200  return new ArrayIterator($this->data);
201  }
$this data['403_header']

◆ has()

Slim\Collection::has (   $key)

Does this collection have a given key?

Parameters
string$keyThe data key
Returns
bool

Implements Slim\Interfaces\CollectionInterface.

Definition at line 107 of file Collection.php.

References $key, and data.

Referenced by Slim\Http\UploadedFile\createFromEnvironment(), and Slim\Http\Uri\createFromEnvironment().

108  {
109  return array_key_exists($key, $this->data);
110  }
$this data['403_header']
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ keys()

Slim\Collection::keys ( )

Get collection keys.

Returns
array The collection's source data keys

Definition at line 95 of file Collection.php.

References data.

96  {
97  return array_keys($this->data);
98  }
$this data['403_header']

◆ 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.

References $key.

142  {
143  return $this->has($key);
144  }
has($key)
Does this collection have a given key?
Definition: Collection.php:107
$key
Definition: croninfo.php:18

◆ 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.

References $key.

154  {
155  return $this->get($key);
156  }
$key
Definition: croninfo.php:18

◆ 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.

References $key.

165  {
166  $this->set($key, $value);
167  }
$key
Definition: croninfo.php:18

◆ offsetUnset()

Slim\Collection::offsetUnset (   $key)

Remove item from collection.

Parameters
string$keyThe data key

Definition at line 174 of file Collection.php.

References $key.

175  {
176  $this->remove($key);
177  }
$key
Definition: croninfo.php:18

◆ remove()

Slim\Collection::remove (   $key)

Remove item from collection.

Parameters
string$keyThe data key

Implements Slim\Interfaces\CollectionInterface.

Definition at line 117 of file Collection.php.

References $key, and data.

118  {
119  unset($this->data[$key]);
120  }
$this data['403_header']
$key
Definition: croninfo.php:18

◆ 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.

References $key.

74  {
75  foreach ($items as $key => $value) {
76  $this->set($key, $value);
77  }
78  }
$key
Definition: croninfo.php:18

◆ set()

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

Set collection item.

Parameters
string$keyThe data key
mixed$valueThe data value

Implements Slim\Interfaces\CollectionInterface.

Definition at line 50 of file Collection.php.

References $key, and data.

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

51  {
52  $this->data[$key] = $value;
53  }
$this data['403_header']
$key
Definition: croninfo.php:18
+ 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: