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,56 @@
1
+<?php
2
+
3
+namespace Telnyx\ApiOperations;
4
+
5
+/**
6
+ * Trait for listable resources. Adds a `all()` static method to the class.
7
+ *
8
+ * This trait should only be applied to classes that derive from TelnyxObject.
9
+ */
10
+trait All
11
+{
12
+    /**
13
+     * @param array|null $params
14
+     * @param array|string|null $opts
15
+     *
16
+     * @return \Telnyx\Collection of ApiResources
17
+     */
18
+    public static function all($params = null, $opts = null)
19
+    {
20
+        self::_validateParams($params);
21
+
22
+        // Convert filter[] pararms
23
+        if (is_array($params)) {
24
+            foreach ($params as $name => $val) {
25
+
26
+                // Make sure this isn't a page[] param
27
+                if (strpos($name, '[') === false && strpos($name, ']') === false) {
28
+
29
+                    // Enclose param in filter[] and remove old param
30
+                    $params['filter[' . $name . ']'] = $val;
31
+                    unset($params[$name]);
32
+                }
33
+            }
34
+        }
35
+
36
+        $url = static::classUrl();
37
+
38
+        list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
39
+
40
+        // Convert this response to a list or collection object
41
+        $response->json['record_type'] = 'list';
42
+
43
+        $obj = \Telnyx\Util\Util::convertToTelnyxObject($response->json, $opts);
44
+        if (!is_a($obj, 'Telnyx\\Collection')) {
45
+            $class = get_class($obj);
46
+            $message = "Expected type \"Telnyx\\Collection\", got \"$class\" instead";
47
+            throw new \Telnyx\Error\Api($message);
48
+        }
49
+        $obj->setLastResponse($response);
50
+        $obj->setRequestParams($params);
51
+
52
+        // This was a temporary field for convertToTelnyxObject. Remove it.
53
+        unset($obj['record_type']);
54
+        return $obj;
55
+    }
56
+}