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