Dns.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Cloudflare\Zone;
  3. use Cloudflare\Api;
  4. /**
  5. * CloudFlare API wrapper
  6. *
  7. * DNS Record
  8. * CloudFlare DNS records
  9. *
  10. * @author James Bell <james@james-bell.co.uk>
  11. *
  12. * @version 1
  13. */
  14. class Dns extends Api
  15. {
  16. /**
  17. * Create DNS record (permission needed: #dns_records:edit)
  18. * Create a new DNS record for a zone. See the record object definitions for required attributes for each record type
  19. *
  20. * @param string $zone_identifier
  21. * @param string $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF)
  22. * @param string $name DNS record name
  23. * @param string $content DNS record content
  24. * @param int|null $ttl Time to live for DNS record. Value of 1 is 'automatic'
  25. * @param bool|null $proxied Whether to proxy the domain through CloudFlare or not
  26. * @param int|null $priority MX record priority value
  27. * @param array|null $data Additional data required for SRV record
  28. */
  29. public function create($zone_identifier, $type, $name, $content, $ttl = null, $proxied = null, $priority = null, $data = null)
  30. {
  31. $data = [
  32. 'type' => strtoupper($type),
  33. 'name' => $name,
  34. 'content' => $content,
  35. 'ttl' => $ttl,
  36. 'proxied' => $proxied,
  37. 'priority' => $priority,
  38. 'data' => $data,
  39. ];
  40. return $this->post('zones/'.$zone_identifier.'/dns_records', $data);
  41. }
  42. /**
  43. * List DNS Records (permission needed: #dns_records:read)
  44. * List, search, sort, and filter a zones' DNS records.
  45. *
  46. * @param string $zone_identifier
  47. * @param string|null $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF)
  48. * @param string|null $name DNS record name
  49. * @param string|null $content DNS record content
  50. * @param string|null $vanity_name_server_record Flag for records that were created for the vanity name server feature (true, false)
  51. * @param int|null $page Page number of paginated results
  52. * @param int|null $per_page Number of DNS records per page
  53. * @param string|null $order Field to order records by (type, name, content, ttl, proxied)
  54. * @param string|null $direction Direction to order domains (asc, desc)
  55. * @param string|null $match Whether to match all search requirements or at least one (any) (any, all)
  56. */
  57. public function list_records($zone_identifier, $type = null, $name = null, $content = null, $vanity_name_server_record = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null)
  58. {
  59. $data = [
  60. 'type' => $type,
  61. 'name' => $name,
  62. 'content' => $content,
  63. 'vanity_name_server_record' => $vanity_name_server_record,
  64. 'page' => $page,
  65. 'per_page' => $per_page,
  66. 'order' => $order,
  67. 'direction' => $direction,
  68. 'match' => $match,
  69. ];
  70. return $this->get('zones/'.$zone_identifier.'/dns_records', $data);
  71. }
  72. /**
  73. * DNS record details (permission needed: #dns_records:read)
  74. *
  75. * @param string $zone_identifier
  76. * @param string $identifier API item identifier tag
  77. */
  78. public function details($zone_identifier, $identifier)
  79. {
  80. return $this->get('zones/'.$zone_identifier.'/dns_records/'.$identifier);
  81. }
  82. /**
  83. * Update DNS record (permission needed: #dns_records:edit)
  84. *
  85. * @param string $zone_identifier
  86. * @param string $identifier API item identifier tag
  87. * @param string|null $type DNS record type (A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF)
  88. * @param string|null $name DNS record name
  89. * @param string|null $content DNS record content
  90. * @param string|null $ttl Time to live for DNS record. Value of 1 is 'automatic'
  91. * @param bool|null $proxied Whether to proxy the domain through CloudFlare or not
  92. * @param array|null $data Additional data required for SRV record
  93. * @param int|null $priority MX record priority value
  94. */
  95. public function update($zone_identifier, $identifier, $type = null, $name = null, $content = null, $ttl = null, $proxied = null, $data = null, $priority = null)
  96. {
  97. $data = [
  98. 'type' => $type,
  99. 'name' => $name,
  100. 'content' => $content,
  101. 'ttl' => $ttl,
  102. 'proxied' => $proxied,
  103. 'priority' => $priority,
  104. 'data' => $data,
  105. ];
  106. return $this->put('zones/'.$zone_identifier.'/dns_records/'.$identifier, $data);
  107. }
  108. /**
  109. * Update DNS record (permission needed: #dns_records:edit)
  110. *
  111. * @param string $zone_identifier
  112. * @param string $identifier API item identifier tag
  113. */
  114. public function delete_record($zone_identifier, $identifier)
  115. {
  116. return $this->delete('zones/'.$zone_identifier.'/dns_records/'.$identifier);
  117. }
  118. }