| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,46 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace Telnyx\ApiOperations; |
|
| 4 |
+ |
|
| 5 |
+/** |
|
| 6 |
+ * Trait for updatable resources. Adds an `update()` static method and a |
|
| 7 |
+ * `save()` method to the class. |
|
| 8 |
+ * |
|
| 9 |
+ * This trait should only be applied to classes that derive from TelnyxObject. |
|
| 10 |
+ */ |
|
| 11 |
+trait Update |
|
| 12 |
+{
|
|
| 13 |
+ /** |
|
| 14 |
+ * @param string $id The ID of the resource to update. |
|
| 15 |
+ * @param array|null $params |
|
| 16 |
+ * @param array|string|null $opts |
|
| 17 |
+ * |
|
| 18 |
+ * @return \Telnyx\ApiResource The updated resource. |
|
| 19 |
+ */ |
|
| 20 |
+ public static function update($id, $params = null, $opts = null) |
|
| 21 |
+ {
|
|
| 22 |
+ self::_validateParams($params); |
|
| 23 |
+ $url = static::resourceUrl($id); |
|
| 24 |
+ |
|
| 25 |
+ list($response, $opts) = static::_staticRequest('patch', $url, $params, $opts);
|
|
| 26 |
+ $obj = \Telnyx\Util\Util::convertToTelnyxObject($response->json, $opts); |
|
| 27 |
+ $obj->setLastResponse($response); |
|
| 28 |
+ return $obj; |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ /** |
|
| 32 |
+ * @param array|string|null $opts |
|
| 33 |
+ * |
|
| 34 |
+ * @return \Telnyx\ApiResource The saved resource. |
|
| 35 |
+ */ |
|
| 36 |
+ public function save($opts = null) |
|
| 37 |
+ {
|
|
| 38 |
+ $params = $this->serializeParameters(); |
|
| 39 |
+ if (count($params) > 0) {
|
|
| 40 |
+ $url = $this->instanceUrl(); |
|
| 41 |
+ list($response, $opts) = $this->_request('patch', $url, $params, $opts);
|
|
| 42 |
+ $this->refreshFrom($response, $opts); |
|
| 43 |
+ } |
|
| 44 |
+ return $this; |
|
| 45 |
+ } |
|
| 46 |
+} |