PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / vendor / stripe / stripe-php / lib / Util / CaseInsensitiveArray.php

CaseInsensitiveArray.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at vendor/stripe/stripe-php/lib/Util/CaseInsensitiveArray.php

97 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace 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 = static::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 = static::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 = static::maybeLowercase($offset);
74 unset($this->container[$offset]);
75 }
76
77 /**
78 * @return mixed
79 */
80 #[\ReturnTypeWillChange]
81 public function offsetGet($offset)
82 {
83 $offset = static::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