ApiVersion.php
6 months ago
CaseInsensitiveArray.php
6 months ago
DefaultLogger.php
6 months ago
EventTypes.php
6 months ago
LoggerInterface.php
6 months ago
ObjectTypes.php
6 months ago
RandomGenerator.php
6 months ago
RequestOptions.php
6 months ago
Set.php
6 months ago
Util.php
6 months ago
CaseInsensitiveArray.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Stripe\Util; |
| 4 | |
| 5 | /** |
| 6 | * CaseInsensitiveArray is an array-like class that ignores case for keys. |
| 7 | * |
| 8 | * It is used to store HTTP headers. Per RFC 2616, section 4.2: |
| 9 | * Each header field consists of a name followed by a colon (":") and the field value. Field names |
| 10 | * are case-insensitive. |
| 11 | * |
| 12 | * In the context of stripe-php, this is useful because the API will return headers with different |
| 13 | * case depending on whether HTTP/2 is used or not (with HTTP/2, headers are always in lowercase). |
| 14 | */ |
| 15 | class CaseInsensitiveArray implements \ArrayAccess, \Countable, \IteratorAggregate |
| 16 | { |
| 17 | private $container = []; |
| 18 | |
| 19 | public function __construct($initial_array = []) |
| 20 | { |
| 21 | $this->container = \array_change_key_case($initial_array, \CASE_LOWER); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @return int |
| 26 | */ |
| 27 | #[\ReturnTypeWillChange] |
| 28 | public function count() |
| 29 | { |
| 30 | return \count($this->container); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return \ArrayIterator |
| 35 | */ |
| 36 | #[\ReturnTypeWillChange] |
| 37 | public function getIterator() |
| 38 | { |
| 39 | return new \ArrayIterator($this->container); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @return void |
| 44 | */ |
| 45 | #[\ReturnTypeWillChange] |
| 46 | public function offsetSet($offset, $value) |
| 47 | { |
| 48 | $offset = self::maybeLowercase($offset); |
| 49 | if (null === $offset) { |
| 50 | $this->container[] = $value; |
| 51 | } else { |
| 52 | $this->container[$offset] = $value; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return bool |
| 58 | */ |
| 59 | #[\ReturnTypeWillChange] |
| 60 | public function offsetExists($offset) |
| 61 | { |
| 62 | $offset = self::maybeLowercase($offset); |
| 63 | |
| 64 | return isset($this->container[$offset]); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return void |
| 69 | */ |
| 70 | #[\ReturnTypeWillChange] |
| 71 | public function offsetUnset($offset) |
| 72 | { |
| 73 | $offset = self::maybeLowercase($offset); |
| 74 | unset($this->container[$offset]); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return mixed |
| 79 | */ |
| 80 | #[\ReturnTypeWillChange] |
| 81 | public function offsetGet($offset) |
| 82 | { |
| 83 | $offset = self::maybeLowercase($offset); |
| 84 | |
| 85 | return isset($this->container[$offset]) ? $this->container[$offset] : null; |
| 86 | } |
| 87 | |
| 88 | private static function maybeLowercase($v) |
| 89 | { |
| 90 | if (\is_string($v)) { |
| 91 | return \strtolower($v); |
| 92 | } |
| 93 | |
| 94 | return $v; |
| 95 | } |
| 96 | } |
| 97 |