| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,40 @@ |
| 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 |
+ $url = static::classUrl(); |
|
| 23 |
+ |
|
| 24 |
+ list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
|
|
| 25 |
+ |
|
| 26 |
+ // This is needed for nextPage() and previousPage() |
|
| 27 |
+ $response->json['url'] = $url; |
|
| 28 |
+ |
|
| 29 |
+ $obj = \Telnyx\Util\Util::convertToTelnyxObject($response->json, $opts); |
|
| 30 |
+ if (!is_a($obj, \Telnyx\Collection::class)) {
|
|
| 31 |
+ throw new \Telnyx\Exception\UnexpectedValueException( |
|
| 32 |
+ 'Expected type ' . \Telnyx\Collection::class . ', got "' . \get_class($obj) . '" instead.' |
|
| 33 |
+ ); |
|
| 34 |
+ } |
|
| 35 |
+ $obj->setLastResponse($response); |
|
| 36 |
+ $obj->setRequestParams($params); |
|
| 37 |
+ |
|
| 38 |
+ return $obj; |
|
| 39 |
+ } |
|
| 40 |
+} |