- Timestamp:
- 12/06/2021 09:29:00 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php
r52244 r52328 3 3 * Case-insensitive dictionary, suitable for HTTP headers 4 4 * 5 * @package Requests\Utilities 5 * @package Requests 6 * @subpackage Utilities 6 7 */ 7 8 namespace WpOrg\Requests\Utility;9 10 use ArrayAccess;11 use ArrayIterator;12 use IteratorAggregate;13 use ReturnTypeWillChange;14 use WpOrg\Requests\Exception;15 8 16 9 /** 17 10 * Case-insensitive dictionary, suitable for HTTP headers 18 11 * 19 * @package Requests\Utilities 12 * @package Requests 13 * @subpackage Utilities 20 14 */ 21 class CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {15 class Requests_Utility_CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate { 22 16 /** 23 17 * Actual item data … … 25 19 * @var array 26 20 */ 27 protected $data = [];21 protected $data = array(); 28 22 29 23 /** … … 32 26 * @param array $data Dictionary/map to convert to case-insensitive 33 27 */ 34 public function __construct(array $data = []) {35 foreach ($data as $ offset=> $value) {36 $this->offsetSet($ offset, $value);28 public function __construct(array $data = array()) { 29 foreach ($data as $key => $value) { 30 $this->offsetSet($key, $value); 37 31 } 38 32 } … … 41 35 * Check if the given item exists 42 36 * 43 * @param string $ offsetItem key37 * @param string $key Item key 44 38 * @return boolean Does the item exist? 45 39 */ 46 #[ReturnTypeWillChange] 47 public function offsetExists($offset) { 48 if (is_string($offset)) { 49 $offset = strtolower($offset); 50 } 51 52 return isset($this->data[$offset]); 40 public function offsetExists($key) { 41 $key = strtolower($key); 42 return isset($this->data[$key]); 53 43 } 54 44 … … 56 46 * Get the value for the item 57 47 * 58 * @param string $ offsetItem key59 * @return string|null Item value (null if the item key doesn't exist)48 * @param string $key Item key 49 * @return string|null Item value (null if offsetExists is false) 60 50 */ 61 #[ReturnTypeWillChange] 62 public function offsetGet($offset) { 63 if (is_string($offset)) { 64 $offset = strtolower($offset); 65 } 66 67 if (!isset($this->data[$offset])) { 51 public function offsetGet($key) { 52 $key = strtolower($key); 53 if (!isset($this->data[$key])) { 68 54 return null; 69 55 } 70 56 71 return $this->data[$ offset];57 return $this->data[$key]; 72 58 } 73 59 … … 75 61 * Set the given item 76 62 * 77 * @param string $offset Item name 63 * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 64 * 65 * @param string $key Item name 78 66 * @param string $value Item value 79 *80 * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)81 67 */ 82 #[ReturnTypeWillChange] 83 public function offsetSet($offset, $value) { 84 if ($offset === null) { 85 throw new Exception('Object is a dictionary, not a list', 'invalidset'); 68 public function offsetSet($key, $value) { 69 if ($key === null) { 70 throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 86 71 } 87 72 88 if (is_string($offset)) { 89 $offset = strtolower($offset); 90 } 91 92 $this->data[$offset] = $value; 73 $key = strtolower($key); 74 $this->data[$key] = $value; 93 75 } 94 76 … … 96 78 * Unset the given header 97 79 * 98 * @param string $ offset80 * @param string $key 99 81 */ 100 #[ReturnTypeWillChange] 101 public function offsetUnset($offset) { 102 if (is_string($offset)) { 103 $offset = strtolower($offset); 104 } 105 106 unset($this->data[$offset]); 82 public function offsetUnset($key) { 83 unset($this->data[strtolower($key)]); 107 84 } 108 85 … … 110 87 * Get an iterator for the data 111 88 * 112 * @return \ArrayIterator89 * @return ArrayIterator 113 90 */ 114 #[ReturnTypeWillChange]115 91 public function getIterator() { 116 92 return new ArrayIterator($this->data);
Note: See TracChangeset
for help on using the changeset viewer.