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

Headers. More...

+ Inheritance diagram for Slim\Http\Headers:
+ Collaboration diagram for Slim\Http\Headers:

Public Member Functions

 all ()
 Return array of HTTP header names and values. More...
 
 set ($key, $value)
 Set HTTP header value. More...
 
 get ($key, $default=null)
 Get HTTP header value. More...
 
 getOriginalKey ($key, $default=null)
 Get HTTP header key as originally specified. More...
 
 add ($key, $value)
 Add HTTP header value. More...
 
 has ($key)
 Does this collection have a given header? More...
 
 remove ($key)
 Remove header from collection. More...
 
 normalizeKey ($key)
 Normalize header name. More...
 
- Public Member Functions inherited from Slim\Collection
 __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...
 

Static Public Member Functions

static static createFromEnvironment (Environment $environment)
 Create new headers collection with data extracted from the application Environment object. More...
 
static determineAuthorization (Environment $environment)
 If HTTP_AUTHORIZATION does not exist tries to get it from getallheaders() when available. More...
 

Static Protected Attributes

static $special
 

Additional Inherited Members

- Protected Attributes inherited from Slim\Collection
 $data = []
 

Detailed Description

Headers.

This class represents a collection of HTTP headers that is used in both the HTTP request and response objects. It also enables header name case-insensitivity when getting or setting a header value.

Each HTTP header can have multiple values. This class stores values into an array for each header name. When you request a header value, you receive an array of values for that header.

Definition at line 27 of file Headers.php.

Member Function Documentation

◆ add()

Slim\Http\Headers::add (   $key,
  $value 
)

Add HTTP header value.

This method appends a header value. Unlike the set() method, this method appends this new value to any values that already exist for this header name.

Parameters
string$keyThe case-insensitive header name
array | string$valueThe new header value(s)

Implements Slim\Interfaces\Http\HeadersInterface.

Definition at line 173 of file Headers.php.

References $key.

174  {
175  $oldValues = $this->get($key, []);
176  $newValues = is_array($value) ? $value : [$value];
177  $this->set($key, array_merge($oldValues, array_values($newValues)));
178  }
$key
Definition: croninfo.php:18

◆ all()

Slim\Http\Headers::all ( )

Return array of HTTP header names and values.

This method returns the original header name as specified by the end user.

Returns
array

Implements Slim\Interfaces\CollectionInterface.

Definition at line 98 of file Headers.php.

References $key, and $out.

99  {
100  $all = parent::all();
101  $out = [];
102  foreach ($all as $key => $props) {
103  $out[$props['originalKey']] = $props['value'];
104  }
105 
106  return $out;
107  }
$key
Definition: croninfo.php:18

◆ createFromEnvironment()

static static Slim\Http\Headers::createFromEnvironment ( Environment  $environment)
static

Create new headers collection with data extracted from the application Environment object.

Parameters
Environment$environmentThe Slim application Environment
Returns
self

Definition at line 51 of file Headers.php.

References Slim\Collection\$data, and $key.

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

52  {
53  $data = [];
54  $environment = self::determineAuthorization($environment);
55  foreach ($environment as $key => $value) {
56  $key = strtoupper($key);
57  if (isset(static::$special[$key]) || strpos($key, 'HTTP_') === 0) {
58  if ($key !== 'HTTP_CONTENT_LENGTH') {
59  $data[$key] = $value;
60  }
61  }
62  }
63 
64  return new static($data);
65  }
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ determineAuthorization()

static Slim\Http\Headers::determineAuthorization ( Environment  $environment)
static

If HTTP_AUTHORIZATION does not exist tries to get it from getallheaders() when available.

Parameters
Environment$environmentThe Slim application Environment
Returns
Environment

Definition at line 76 of file Headers.php.

References Slim\Collection\get(), and Slim\Collection\set().

77  {
78  $authorization = $environment->get('HTTP_AUTHORIZATION');
79 
80  if (empty($authorization) && is_callable('getallheaders')) {
81  $headers = getallheaders();
82  $headers = array_change_key_case($headers, CASE_LOWER);
83  if (isset($headers['authorization'])) {
84  $environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
85  }
86  }
87 
88  return $environment;
89  }
+ Here is the call graph for this function:

◆ get()

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

Get HTTP header value.

Parameters
string$keyThe case-insensitive header name
mixed$defaultThe default value if key does not exist
Returns
string[]

Implements Slim\Interfaces\CollectionInterface.

Definition at line 137 of file Headers.php.

References $key, Slim\Http\Headers\has(), and Slim\Http\Headers\normalizeKey().

138  {
139  if ($this->has($key)) {
140  return parent::get($this->normalizeKey($key))['value'];
141  }
142 
143  return $default;
144  }
has($key)
Does this collection have a given header?
Definition: Headers.php:187
normalizeKey($key)
Normalize header name.
Definition: Headers.php:213
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getOriginalKey()

Slim\Http\Headers::getOriginalKey (   $key,
  $default = null 
)

Get HTTP header key as originally specified.

Parameters
string$keyThe case-insensitive header name
mixed$defaultThe default value if key does not exist
Returns
string

Definition at line 154 of file Headers.php.

References $key, Slim\Http\Headers\has(), and Slim\Http\Headers\normalizeKey().

155  {
156  if ($this->has($key)) {
157  return parent::get($this->normalizeKey($key))['originalKey'];
158  }
159 
160  return $default;
161  }
has($key)
Does this collection have a given header?
Definition: Headers.php:187
normalizeKey($key)
Normalize header name.
Definition: Headers.php:213
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ has()

Slim\Http\Headers::has (   $key)

Does this collection have a given header?

Parameters
string$keyThe case-insensitive header name
Returns
bool

Implements Slim\Interfaces\CollectionInterface.

Definition at line 187 of file Headers.php.

References $key, and Slim\Http\Headers\normalizeKey().

Referenced by Slim\Http\Headers\get(), and Slim\Http\Headers\getOriginalKey().

188  {
189  return parent::has($this->normalizeKey($key));
190  }
normalizeKey($key)
Normalize header name.
Definition: Headers.php:213
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizeKey()

Slim\Http\Headers::normalizeKey (   $key)

Normalize header name.

This method transforms header names into a normalized form. This is how we enable case-insensitive header names in the other methods in this class.

Parameters
string$keyThe case-insensitive header name
Returns
string Normalized header name

Implements Slim\Interfaces\Http\HeadersInterface.

Definition at line 213 of file Headers.php.

References $key.

Referenced by Slim\Http\Headers\get(), Slim\Http\Headers\getOriginalKey(), Slim\Http\Headers\has(), Slim\Http\Headers\remove(), and Slim\Http\Headers\set().

214  {
215  $key = strtr(strtolower($key), '_', '-');
216  if (strpos($key, 'http-') === 0) {
217  $key = substr($key, 5);
218  }
219 
220  return $key;
221  }
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ remove()

Slim\Http\Headers::remove (   $key)

Remove header from collection.

Parameters
string$keyThe case-insensitive header name

Implements Slim\Interfaces\CollectionInterface.

Definition at line 197 of file Headers.php.

References $key, Slim\Http\Headers\normalizeKey(), and remove().

198  {
200  }
normalizeKey($key)
Normalize header name.
Definition: Headers.php:213
remove()
Definition: remove.php:2
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ set()

Slim\Http\Headers::set (   $key,
  $value 
)

Set HTTP header value.

This method sets a header value. It replaces any values that may already exist for the header name.

Parameters
string$keyThe case-insensitive header name
string$valueThe header value

Implements Slim\Interfaces\CollectionInterface.

Definition at line 118 of file Headers.php.

References $key, and Slim\Http\Headers\normalizeKey().

119  {
120  if (!is_array($value)) {
121  $value = [$value];
122  }
123  parent::set($this->normalizeKey($key), [
124  'value' => $value,
125  'originalKey' => $key
126  ]);
127  }
normalizeKey($key)
Normalize header name.
Definition: Headers.php:213
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $special

Slim\Http\Headers::$special
staticprotected
Initial value:
= [
'CONTENT_TYPE' => 1

Definition at line 34 of file Headers.php.


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