Changeset 52328 for trunk/src/wp-includes/Requests/Response/Headers.php
- Timestamp:
- 12/06/2021 09:29:00 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Response/Headers.php
r52244 r52328 6 6 */ 7 7 8 namespace WpOrg\Requests\Response;9 10 use WpOrg\Requests\Exception;11 use WpOrg\Requests\Exception\InvalidArgument;12 use WpOrg\Requests\Utility\CaseInsensitiveDictionary;13 use WpOrg\Requests\Utility\FilteredIterator;14 15 8 /** 16 9 * Case-insensitive dictionary, suitable for HTTP headers … … 18 11 * @package Requests 19 12 */ 20 class Headers extendsCaseInsensitiveDictionary {13 class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary { 21 14 /** 22 15 * Get the given header 23 16 * 24 * Unlike {@see \WpOrg\Requests\Response\Headers::getValues()}, this returns a string. If there are17 * Unlike {@see self::getValues()}, this returns a string. If there are 25 18 * multiple values, it concatenates them with a comma as per RFC2616. 26 19 * … … 28 21 * Set-Cookie headers. 29 22 * 30 * @param string $ offset23 * @param string $key 31 24 * @return string|null Header value 32 25 */ 33 public function offsetGet($offset) { 34 if (is_string($offset)) { 35 $offset = strtolower($offset); 36 } 37 38 if (!isset($this->data[$offset])) { 26 public function offsetGet($key) { 27 $key = strtolower($key); 28 if (!isset($this->data[$key])) { 39 29 return null; 40 30 } 41 31 42 return $this->flatten($this->data[$ offset]);32 return $this->flatten($this->data[$key]); 43 33 } 44 34 … … 46 36 * Set the given item 47 37 * 48 * @param string $offset Item name 38 * @throws Requests_Exception On attempting to use dictionary as list (`invalidset`) 39 * 40 * @param string $key Item name 49 41 * @param string $value Item value 50 *51 * @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)52 42 */ 53 public function offsetSet($ offset, $value) {54 if ($ offset=== null) {55 throw new Exception('Object is a dictionary, not a list', 'invalidset');43 public function offsetSet($key, $value) { 44 if ($key === null) { 45 throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); 56 46 } 57 47 58 if (is_string($offset)) { 59 $offset = strtolower($offset); 48 $key = strtolower($key); 49 50 if (!isset($this->data[$key])) { 51 $this->data[$key] = array(); 60 52 } 61 53 62 if (!isset($this->data[$offset])) { 63 $this->data[$offset] = []; 64 } 65 66 $this->data[$offset][] = $value; 54 $this->data[$key][] = $value; 67 55 } 68 56 … … 70 58 * Get all values for a given header 71 59 * 72 * @param string $ offset60 * @param string $key 73 61 * @return array|null Header values 74 *75 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.76 62 */ 77 public function getValues($offset) { 78 if (!is_string($offset) && !is_int($offset)) { 79 throw InvalidArgument::create(1, '$offset', 'string|int', gettype($offset)); 80 } 81 82 $offset = strtolower($offset); 83 if (!isset($this->data[$offset])) { 63 public function getValues($key) { 64 $key = strtolower($key); 65 if (!isset($this->data[$key])) { 84 66 return null; 85 67 } 86 68 87 return $this->data[$ offset];69 return $this->data[$key]; 88 70 } 89 71 … … 96 78 * @param string|array $value Value to flatten 97 79 * @return string Flattened value 98 *99 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or an array.100 80 */ 101 81 public function flatten($value) { 102 if (is_ string($value)) {103 return $value;82 if (is_array($value)) { 83 $value = implode(',', $value); 104 84 } 105 85 106 if (is_array($value)) { 107 return implode(',', $value); 108 } 109 110 throw InvalidArgument::create(1, '$value', 'string|array', gettype($value)); 86 return $value; 111 87 } 112 88 … … 114 90 * Get an iterator for the data 115 91 * 116 * Converts the internally stored values to a comma-separated string if there is more 117 * than one value for a key. 118 * 119 * @return \ArrayIterator 92 * Converts the internal 93 * @return ArrayIterator 120 94 */ 121 95 public function getIterator() { 122 return new FilteredIterator($this->data, [$this, 'flatten']);96 return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten')); 123 97 } 124 98 }
Note: See TracChangeset
for help on using the changeset viewer.