[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @category Services 5 * @package Services_Twilio 6 * @author Neuman Vong <[email protected]> 7 * @license http://creativecommons.org/licenses/MIT/ MIT 8 * @link http://pear.php.net/package/Services_Twilio 9 */ 10 11 /** 12 * Abstraction of an instance resource from the Twilio API. 13 */ 14 abstract class Services_Twilio_InstanceResource extends Services_Twilio_Resource { 15 16 /** 17 * Make a request to the API to update an instance resource 18 * 19 * :param mixed $params: An array of updates, or a property name 20 * :param mixed $value: A value with which to update the resource 21 * 22 * :rtype: null 23 * :throws: a :php:class:`RestException <Services_Twilio_RestException>` if 24 * the update fails. 25 */ 26 public function update($params, $value = null) 27 { 28 if (!is_array($params)) { 29 $params = array($params => $value); 30 } 31 $decamelizedParams = $this->client->createData($this->uri, $params); 32 $this->updateAttributes($decamelizedParams); 33 } 34 35 /* 36 * Add all properties from an associative array (the JSON response body) as 37 * properties on this instance resource, except the URI 38 * 39 * :param stdClass $params: An object containing all of the parameters of 40 * this instance 41 * :return: Nothing, this is purely side effecting 42 * :rtype: null 43 */ 44 public function updateAttributes($params) { 45 unset($params->uri); 46 foreach ($params as $name => $value) { 47 $this->$name = $value; 48 } 49 } 50 51 /** 52 * Get the value of a property on this resource. 53 * 54 * Instead of defining all of the properties of an object directly, we rely 55 * on the API to tell us which properties an object has. This method will 56 * query the API to retrieve a property for an object, if it is not already 57 * set on the object. 58 * 59 * If the call is to a subresource, eg ``$client->account->messages``, no 60 * request is made. 61 * 62 * To help with lazy HTTP requests, we don't actually retrieve an object 63 * from the API unless you really need it. Hence, this function may make API 64 * requests even if the property you're requesting isn't available on the 65 * resource. 66 * 67 * :param string $key: The property name 68 * 69 * :return mixed: Could be anything. 70 * :throws: a :php:class:`RestException <Services_Twilio_RestException>` if 71 * the update fails. 72 */ 73 public function __get($key) 74 { 75 if ($subresource = $this->getSubresources($key)) { 76 return $subresource; 77 } 78 if (!isset($this->$key)) { 79 $params = $this->client->retrieveData($this->uri); 80 $this->updateAttributes($params); 81 } 82 return $this->$key; 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |