Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

  • AsyncResponse
  • Domain
  • Object
  • PtrRecord
  • Record
  • Service
  • Subdomain
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright Copyright 2013 Rackspace US, Inc. See COPYING for licensing information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
  7:  * @version   1.6.0
  8:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  9:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 10:  */
 11: 
 12: namespace OpenCloud\DNS;
 13: 
 14: use OpenCloud\Common\Lang;
 15: use OpenCloud\Common\Exceptions;
 16: 
 17: /**
 18:  * PTR records are used for reverse DNS
 19:  *
 20:  * The PtrRecord object is nearly identical with the Record object. However,
 21:  * the PtrRecord is a child of the service, and not a child of a Domain.
 22:  */
 23: class PtrRecord extends Record 
 24: {
 25: 
 26:     public $server;
 27: 
 28:     protected static $json_name = false;
 29:     protected static $json_collection_name = 'records';
 30:     protected static $url_resource = 'rdns';
 31: 
 32:     private $link_rel;
 33:     private $link_href;
 34: 
 35:     /**
 36:      * constructur ensures that the record type is PTR
 37:      */
 38:     public function __construct($parent, $info = null) 
 39:     {
 40:         $this->type = 'PTR';
 41:         parent::__construct($parent, $info);
 42:         if ($this->type != 'PTR') {
 43:             throw new Exceptions\RecordTypeError(sprintf(
 44:                 Lang::translate('Invalid record type [%s], must be PTR'), 
 45:                 $this->type
 46:             ));
 47:         }
 48:     }
 49: 
 50:     /**
 51:      * specialized DNS PTR URL requires server service name and href
 52:      */
 53:     public function url($subresource = null, $params = array()) 
 54:     {
 55:         $subresource = $subresource ?: self::$url_resource;
 56:         return $this->getParent()->url($subresource, $params);
 57:     }
 58: 
 59:     /**
 60:      * DNS PTR Create() method requires a server
 61:      *
 62:      * Generally called as `Create(array('server'=>$server))`
 63:      */
 64:     public function create($params = array()) 
 65:     {
 66:         $this->populate($params, false);
 67:         $this->link_rel = $this->server->Service()->name();
 68:         $this->link_href = $this->server->url();
 69:         return parent::create();
 70:     }
 71: 
 72:     /**
 73:      * DNS PTR Update() method requires a server
 74:      */
 75:     public function update($params = array()) 
 76:     {
 77:         $this->populate($params, false);
 78:         $this->link_rel = $this->server->Service()->Name();
 79:         $this->link_href = $this->server->Url();
 80:         return parent::update();
 81:     }
 82: 
 83:     /**
 84:      * DNS PTR Delete() method requires a server
 85:      *
 86:      * Note that delete will remove ALL PTR records associated with the device
 87:      * unless you pass in the parameter ip={ip address}
 88:      *
 89:      */
 90:     public function delete() 
 91:     {
 92:         $this->link_rel = $this->server->Service()->Name();
 93:         $this->link_href = $this->server->Url();
 94:         
 95:         $params = array('href' => $this->link_href);
 96:         if (!empty($this->data)) {
 97:             $params['ip'] = $this->data;
 98:         }
 99:         
100:         $url = $this->url('rdns/' . $this->link_rel, $params);
101: 
102:         // perform the request
103:         $response = $this->getService()->request($url, 'DELETE');
104: 
105:         // return the AsyncResponse object
106:         return new AsyncResponse($this->getService(), $response->HttpBody());
107:     }
108: 
109:     /**
110:      * Specialized JSON for DNS PTR creates and updates
111:      */
112:     protected function createJson() 
113:     {
114:         return (object) array(
115:             'recordsList' => parent::createJson(),
116:             'link' => array(
117:                 'href' => $this->link_href,
118:                 'rel'  => $this->link_rel
119:             )
120:         );
121:     }
122: 
123:     /**
124:      * The Update() JSON requires a record ID
125:      */
126:     protected function updateJson($params = array()) 
127:     {
128:         $this->populate($params, false);
129:         $object = $this->createJson();
130:         $object->recordsList->records[0]->id = $this->id;
131:         return $object;
132:     }
133: 
134: }
135: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0