Browse code

Added README.md appinfo/info.xml appinfo/signature.json lib/Controller/AuthorApiController.php and the providers directory

DoubleBastionAdmin authored on 20/08/2022 16:33:00
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,74 @@
1
+<?php
2
+
3
+namespace Telnyx\Util;
4
+
5
+use ArrayAccess;
6
+
7
+/**
8
+ * CaseInsensitiveArray is an array-like class that ignores case for keys.
9
+ *
10
+ * It is used to store HTTP headers. Per RFC 2616, section 4.2:
11
+ * Each header field consists of a name followed by a colon (":") and the field value. Field names
12
+ * are case-insensitive.
13
+ *
14
+ * In the context of telnyx-php, this is useful because the API will return headers with different
15
+ * case depending on whether HTTP/2 is used or not (with HTTP/2, headers are always in lowercase).
16
+ */
17
+class CaseInsensitiveArray implements \ArrayAccess, \Countable, \IteratorAggregate
18
+{
19
+    private $container = [];
20
+
21
+    public function __construct($initial_array = [])
22
+    {
23
+        $this->container = \array_change_key_case($initial_array, \CASE_LOWER);
24
+    }
25
+
26
+    public function count()
27
+    {
28
+        return \count($this->container);
29
+    }
30
+
31
+    public function getIterator()
32
+    {
33
+        return new \ArrayIterator($this->container);
34
+    }
35
+
36
+    public function offsetSet($offset, $value)
37
+    {
38
+        $offset = static::maybeLowercase($offset);
39
+        if (null === $offset) {
40
+            $this->container[] = $value;
41
+        } else {
42
+            $this->container[$offset] = $value;
43
+        }
44
+    }
45
+
46
+    public function offsetExists($offset)
47
+    {
48
+        $offset = static::maybeLowercase($offset);
49
+
50
+        return isset($this->container[$offset]);
51
+    }
52
+
53
+    public function offsetUnset($offset)
54
+    {
55
+        $offset = static::maybeLowercase($offset);
56
+        unset($this->container[$offset]);
57
+    }
58
+
59
+    public function offsetGet($offset)
60
+    {
61
+        $offset = static::maybeLowercase($offset);
62
+
63
+        return isset($this->container[$offset]) ? $this->container[$offset] : null;
64
+    }
65
+
66
+    private static function maybeLowercase($v)
67
+    {
68
+        if (\is_string($v)) {
69
+            return \strtolower($v);
70
+        }
71
+
72
+        return $v;
73
+    }
74
+}