Domain.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Twilio;
  3. use Twilio\Rest\Client;
  4. /**
  5. * Class Domain
  6. * Abstracts a Twilio sub domain
  7. * @package Twilio
  8. */
  9. abstract class Domain {
  10. /**
  11. * @var \Twilio\Rest\Client Twilio Client
  12. */
  13. protected $client;
  14. /**
  15. * @var string Base URL for this domain
  16. */
  17. protected $baseUrl;
  18. /**
  19. * Construct a new Domain
  20. * @param \Twilio\Rest\Client $client used to communicate with Twilio
  21. */
  22. public function __construct(Client $client) {
  23. $this->client = $client;
  24. $this->baseUrl = '';
  25. }
  26. /**
  27. * Translate version relative URIs into absolute URLs
  28. *
  29. * @param string $uri Version relative URI
  30. * @return string Absolute URL for this domain
  31. */
  32. public function absoluteUrl($uri) {
  33. return implode('/', array(trim($this->baseUrl, '/'), trim($uri, '/')));
  34. }
  35. /**
  36. * Make an HTTP request to the domain
  37. *
  38. * @param string $method HTTP Method to make the request with
  39. * @param string $uri Relative uri to make a request to
  40. * @param array $params Query string arguments
  41. * @param array $data Post form data
  42. * @param array $headers HTTP headers to send with the request
  43. * @param string $user User to authenticate as
  44. * @param string $password Password
  45. * @param null $timeout Request timeout
  46. * @return \Twilio\Http\Response the response for the request
  47. */
  48. public function request($method, $uri, $params = array(), $data = array(),
  49. $headers = array(), $user = null, $password=null,
  50. $timeout=null) {
  51. $url = $this->absoluteUrl($uri);
  52. return $this->client->request(
  53. $method,
  54. $url,
  55. $params,
  56. $data,
  57. $headers,
  58. $user,
  59. $password,
  60. $timeout
  61. );
  62. }
  63. /**
  64. * @return \Twilio\Rest\Client
  65. */
  66. public function getClient() {
  67. return $this->client;
  68. }
  69. public function __toString() {
  70. return '[Domain]';
  71. }
  72. }