Requests_Utility_CaseInsensitiveDictionary

Case-insensitive dictionary, suitable for HTTP headers.

Defined (1)

The class is defined in the following location(s).

/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php  
  1. class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate { 
  2. /** 
  3. * Actual item data 
  4. * @var array 
  5. */ 
  6. protected $data = array(); 
  7.  
  8. /** 
  9. * Creates a case insensitive dictionary. 
  10. * @param array $data Dictionary/map to convert to case-insensitive 
  11. */ 
  12. public function __construct(array $data = array()) { 
  13. foreach ($data as $key => $value) { 
  14. $this->offsetSet($key, $value); 
  15.  
  16. /** 
  17. * Check if the given item exists 
  18. * @param string $key Item key 
  19. * @return boolean Does the item exist? 
  20. */ 
  21. public function offsetExists($key) { 
  22. $key = strtolower($key); 
  23. return isset($this->data[$key]); 
  24.  
  25. /** 
  26. * Get the value for the item 
  27. * @param string $key Item key 
  28. * @return string Item value 
  29. */ 
  30. public function offsetGet($key) { 
  31. $key = strtolower($key); 
  32. if (!isset($this->data[$key])) { 
  33. return null; 
  34.  
  35. return $this->data[$key]; 
  36.  
  37. /** 
  38. * Set the given item 
  39. * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 
  40. * @param string $key Item name 
  41. * @param string $value Item value 
  42. */ 
  43. public function offsetSet($key, $value) { 
  44. if ($key === null) { 
  45. throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 
  46.  
  47. $key = strtolower($key); 
  48. $this->data[$key] = $value; 
  49.  
  50. /** 
  51. * Unset the given header 
  52. * @param string $key 
  53. */ 
  54. public function offsetUnset($key) { 
  55. unset($this->data[strtolower($key)]); 
  56.  
  57. /** 
  58. * Get an iterator for the data 
  59. * @return ArrayIterator 
  60. */ 
  61. public function getIterator() { 
  62. return new ArrayIterator($this->data); 
  63.  
  64. /** 
  65. * Get the headers as an array 
  66. * @return array Header data 
  67. */ 
  68. public function getAll() { 
  69. return $this->data;