3
* Case-insensitive dictionary, suitable for HTTP headers
6
* @subpackage Utilities
10
* Case-insensitive dictionary, suitable for HTTP headers
13
* @subpackage Utilities
15
class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
21
protected $data = array();
24
* Creates a case insensitive dictionary.
26
* @param array $data Dictionary/map to convert to case-insensitive
28
public function __construct(array $data = array()) {
29
foreach ($data as $key => $value) {
30
$this->offsetSet($key, $value);
35
* Check if the given item exists
37
* @param string $key Item key
38
* @return boolean Does the item exist?
40
public function offsetExists($key) {
41
$key = strtolower($key);
42
return isset($this->data[$key]);
46
* Get the value for the item
48
* @param string $key Item key
49
* @return string Item value
51
public function offsetGet($key) {
52
$key = strtolower($key);
53
if (!isset($this->data[$key])) {
57
return $this->data[$key];
63
* @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
65
* @param string $key Item name
66
* @param string $value Item value
68
public function offsetSet($key, $value) {
70
throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
73
$key = strtolower($key);
74
$this->data[$key] = $value;
78
* Unset the given header
82
public function offsetUnset($key) {
83
unset($this->data[strtolower($key)]);
87
* Get an iterator for the data
89
* @return ArrayIterator
91
public function getIterator() {
92
return new ArrayIterator($this->data);
96
* Get the headers as an array
98
* @return array Header data
100
public function getAll() {