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 * Check if the given item exists
26 * @param string $key Item key
27 * @return boolean Does the item exist?
29 public function offsetExists($key) {
30 $key = strtolower($key);
31 return isset($this->data[$key]);
35 * Get the value for the item
37 * @param string $key Item key
38 * @return string Item value
40 public function offsetGet($key) {
41 $key = strtolower($key);
42 if (!isset($this->data[$key]))
45 return $this->data[$key];
51 * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`)
53 * @param string $key Item name
54 * @param string $value Item value
56 public function offsetSet($key, $value) {
58 throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
61 $key = strtolower($key);
62 $this->data[$key] = $value;
66 * Unset the given header
70 public function offsetUnset($key) {
71 unset($this->data[strtolower($key)]);
75 * Get an iterator for the data
77 * @return ArrayIterator
79 public function getIterator() {
80 return new ArrayIterator($this->data);
84 * Get the headers as an array
86 * @return array Header data
88 public function getAll() {