PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Twilio/Rest/Proxy/V1/ServiceContext.php

http://github.com/twilio/twilio-php
PHP | 178 lines | 82 code | 25 blank | 71 comment | 5 complexity | f3dd74a0d0ad5b505db06d0c7e6fae9f MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * This code was generated by
  4. * \ / _ _ _| _ _
  5. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  6. * / /
  7. */
  8. namespace Twilio\Rest\Proxy\V1;
  9. use Twilio\Exceptions\TwilioException;
  10. use Twilio\InstanceContext;
  11. use Twilio\ListResource;
  12. use Twilio\Options;
  13. use Twilio\Rest\Proxy\V1\Service\PhoneNumberList;
  14. use Twilio\Rest\Proxy\V1\Service\SessionList;
  15. use Twilio\Rest\Proxy\V1\Service\ShortCodeList;
  16. use Twilio\Values;
  17. use Twilio\Version;
  18. /**
  19. * PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
  20. *
  21. * @property SessionList $sessions
  22. * @property PhoneNumberList $phoneNumbers
  23. * @property ShortCodeList $shortCodes
  24. * @method \Twilio\Rest\Proxy\V1\Service\SessionContext sessions(string $sid)
  25. * @method \Twilio\Rest\Proxy\V1\Service\PhoneNumberContext phoneNumbers(string $sid)
  26. * @method \Twilio\Rest\Proxy\V1\Service\ShortCodeContext shortCodes(string $sid)
  27. */
  28. class ServiceContext extends InstanceContext {
  29. protected $_sessions;
  30. protected $_phoneNumbers;
  31. protected $_shortCodes;
  32. /**
  33. * Initialize the ServiceContext
  34. *
  35. * @param Version $version Version that contains the resource
  36. * @param string $sid The unique string that identifies the resource
  37. */
  38. public function __construct(Version $version, $sid) {
  39. parent::__construct($version);
  40. // Path Solution
  41. $this->solution = ['sid' => $sid, ];
  42. $this->uri = '/Services/' . \rawurlencode($sid) . '';
  43. }
  44. /**
  45. * Fetch the ServiceInstance
  46. *
  47. * @return ServiceInstance Fetched ServiceInstance
  48. * @throws TwilioException When an HTTP error occurs.
  49. */
  50. public function fetch(): ServiceInstance {
  51. $payload = $this->version->fetch('GET', $this->uri);
  52. return new ServiceInstance($this->version, $payload, $this->solution['sid']);
  53. }
  54. /**
  55. * Delete the ServiceInstance
  56. *
  57. * @return bool True if delete succeeds, false otherwise
  58. * @throws TwilioException When an HTTP error occurs.
  59. */
  60. public function delete(): bool {
  61. return $this->version->delete('DELETE', $this->uri);
  62. }
  63. /**
  64. * Update the ServiceInstance
  65. *
  66. * @param array|Options $options Optional Arguments
  67. * @return ServiceInstance Updated ServiceInstance
  68. * @throws TwilioException When an HTTP error occurs.
  69. */
  70. public function update(array $options = []): ServiceInstance {
  71. $options = new Values($options);
  72. $data = Values::of([
  73. 'UniqueName' => $options['uniqueName'],
  74. 'DefaultTtl' => $options['defaultTtl'],
  75. 'CallbackUrl' => $options['callbackUrl'],
  76. 'GeoMatchLevel' => $options['geoMatchLevel'],
  77. 'NumberSelectionBehavior' => $options['numberSelectionBehavior'],
  78. 'InterceptCallbackUrl' => $options['interceptCallbackUrl'],
  79. 'OutOfSessionCallbackUrl' => $options['outOfSessionCallbackUrl'],
  80. 'ChatInstanceSid' => $options['chatInstanceSid'],
  81. ]);
  82. $payload = $this->version->update('POST', $this->uri, [], $data);
  83. return new ServiceInstance($this->version, $payload, $this->solution['sid']);
  84. }
  85. /**
  86. * Access the sessions
  87. */
  88. protected function getSessions(): SessionList {
  89. if (!$this->_sessions) {
  90. $this->_sessions = new SessionList($this->version, $this->solution['sid']);
  91. }
  92. return $this->_sessions;
  93. }
  94. /**
  95. * Access the phoneNumbers
  96. */
  97. protected function getPhoneNumbers(): PhoneNumberList {
  98. if (!$this->_phoneNumbers) {
  99. $this->_phoneNumbers = new PhoneNumberList($this->version, $this->solution['sid']);
  100. }
  101. return $this->_phoneNumbers;
  102. }
  103. /**
  104. * Access the shortCodes
  105. */
  106. protected function getShortCodes(): ShortCodeList {
  107. if (!$this->_shortCodes) {
  108. $this->_shortCodes = new ShortCodeList($this->version, $this->solution['sid']);
  109. }
  110. return $this->_shortCodes;
  111. }
  112. /**
  113. * Magic getter to lazy load subresources
  114. *
  115. * @param string $name Subresource to return
  116. * @return ListResource The requested subresource
  117. * @throws TwilioException For unknown subresources
  118. */
  119. public function __get(string $name): ListResource {
  120. if (\property_exists($this, '_' . $name)) {
  121. $method = 'get' . \ucfirst($name);
  122. return $this->$method();
  123. }
  124. throw new TwilioException('Unknown subresource ' . $name);
  125. }
  126. /**
  127. * Magic caller to get resource contexts
  128. *
  129. * @param string $name Resource to return
  130. * @param array $arguments Context parameters
  131. * @return InstanceContext The requested resource context
  132. * @throws TwilioException For unknown resource
  133. */
  134. public function __call(string $name, array $arguments): InstanceContext {
  135. $property = $this->$name;
  136. if (\method_exists($property, 'getContext')) {
  137. return \call_user_func_array(array($property, 'getContext'), $arguments);
  138. }
  139. throw new TwilioException('Resource does not have a context');
  140. }
  141. /**
  142. * Provide a friendly representation
  143. *
  144. * @return string Machine friendly representation
  145. */
  146. public function __toString(): string {
  147. $context = [];
  148. foreach ($this->solution as $key => $value) {
  149. $context[] = "$key=$value";
  150. }
  151. return '[Twilio.Proxy.V1.ServiceContext ' . \implode(' ', $context) . ']';
  152. }
  153. }