diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to '')
-rw-r--r-- | vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php | 165 |
1 files changed, 93 insertions, 72 deletions
diff --git a/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php b/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php index 670ab0b..ce6bd3a 100644 --- a/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php +++ b/vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php @@ -1,72 +1,93 @@ -<?php - -namespace Stripe\Util; - -/** - * CaseInsensitiveArray is an array-like class that ignores case for keys. - * - * It is used to store HTTP headers. Per RFC 2616, section 4.2: - * Each header field consists of a name followed by a colon (":") and the field value. Field names - * are case-insensitive. - * - * In the context of stripe-php, this is useful because the API will return headers with different - * case depending on whether HTTP/2 is used or not (with HTTP/2, headers are always in lowercase). - */ -class CaseInsensitiveArray implements \ArrayAccess, \Countable, \IteratorAggregate -{ - private $container = []; - - public function __construct($initial_array = []) - { - $this->container = \array_change_key_case($initial_array, \CASE_LOWER); - } - - public function count() - { - return \count($this->container); - } - - public function getIterator() - { - return new \ArrayIterator($this->container); - } - - public function offsetSet($offset, $value) - { - $offset = static::maybeLowercase($offset); - if (null === $offset) { - $this->container[] = $value; - } else { - $this->container[$offset] = $value; - } - } - - public function offsetExists($offset) - { - $offset = static::maybeLowercase($offset); - - return isset($this->container[$offset]); - } - - public function offsetUnset($offset) - { - $offset = static::maybeLowercase($offset); - unset($this->container[$offset]); - } - - public function offsetGet($offset) - { - $offset = static::maybeLowercase($offset); - - return isset($this->container[$offset]) ? $this->container[$offset] : null; - } - - private static function maybeLowercase($v) - { - if (\is_string($v)) { - return \strtolower($v); - } - - return $v; - } -} +<?php
+
+namespace Stripe\Util;
+
+/**
+ * CaseInsensitiveArray is an array-like class that ignores case for keys.
+ *
+ * It is used to store HTTP headers. Per RFC 2616, section 4.2:
+ * Each header field consists of a name followed by a colon (":") and the field value. Field names
+ * are case-insensitive.
+ *
+ * In the context of stripe-php, this is useful because the API will return headers with different
+ * case depending on whether HTTP/2 is used or not (with HTTP/2, headers are always in lowercase).
+ */
+class CaseInsensitiveArray implements \ArrayAccess, \Countable, \IteratorAggregate
+{
+ private $container = [];
+
+ public function __construct($initial_array = [])
+ {
+ $this->container = \array_change_key_case($initial_array, \CASE_LOWER);
+ }
+
+ #[\ReturnTypeWillChange]
+ public function count()
+ {
+ return \count($this->container);
+ }
+
+ /**
+ * @return \ArrayIterator
+ */
+ #[\ReturnTypeWillChange]
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->container);
+ }
+
+ /**
+ * @return void
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetSet($offset, $value)
+ {
+ $offset = static::maybeLowercase($offset);
+ if (null === $offset) {
+ $this->container[] = $value;
+ } else {
+ $this->container[$offset] = $value;
+ }
+ }
+
+ /**
+ * @return bool
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetExists($offset)
+ {
+ $offset = static::maybeLowercase($offset);
+
+ return isset($this->container[$offset]);
+ }
+
+ /**
+ * @return void
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetUnset($offset)
+ {
+ $offset = static::maybeLowercase($offset);
+ unset($this->container[$offset]);
+ }
+
+ /**
+ * @return mixed
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetGet($offset)
+ {
+ $offset = static::maybeLowercase($offset);
+
+ return isset($this->container[$offset]) ? $this->container[$offset] : null;
+ }
+
+ private static function maybeLowercase($v)
+ {
+ if (\is_string($v)) {
+ return \strtolower($v);
+ }
+
+ return $v;
+ }
+}
|