Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • AsyncResponse
  • Domain
  • Object
  • PtrRecord
  • Record
  • Subdomain
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
  7:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\DNS\Resource;
 12: 
 13: use OpenCloud\Common\Http\Message\Formatter;
 14: 
 15: /**
 16:  * The Domain class represents a single domain
 17:  *
 18:  * Note that the `Subdomain` class is defined in this same file because of
 19:  * mutual dependencies.
 20:  */
 21: class Domain extends Object
 22: {
 23: 
 24:     public $id;
 25:     public $accountId;
 26:     public $ttl;
 27:     public $updated;
 28:     public $emailAddress;
 29:     public $created;
 30:     public $name;
 31:     public $comment;
 32: 
 33:     protected static $json_name = FALSE;
 34:     protected static $json_collection_name = 'domains';
 35:     protected static $url_resource = 'domains';
 36: 
 37:     protected $createKeys = array(
 38:         'name',
 39:         'emailAddress',
 40:         'ttl',
 41:         'comment'
 42:     );
 43: 
 44:     protected $updateKeys = array(
 45:         'emailAddress',
 46:         'ttl',
 47:         'comment'
 48:     );
 49: 
 50:     private $records = array();
 51:     private $subdomains = array();
 52: 
 53:     /**
 54:      * returns a Record object
 55:      *
 56:      * Note that this method is available at the DNS level, but only for
 57:      * PTR records.
 58:      *
 59:      * @return Record
 60:      */
 61:     public function record($info = null)
 62:     {
 63:         $resource = new Record($this->getService());
 64:         $resource->setParent($this)->populate($info);
 65:         return $resource;
 66:     }
 67: 
 68:     /**
 69:      * returns a Collection of Record objects
 70:      *
 71:      * @param array $filter query-string parameters
 72:      * @return \OpenCloud\Collection
 73:      */
 74:     public function recordList($filter = array())
 75:     {
 76:         return $this->getParent()->collection(
 77:             'OpenCloud\DNS\Resource\Record', null, $this, $filter
 78:         );
 79:     }
 80: 
 81:     /**
 82:      * returns a Subdomain object (child of current domain)
 83:      *
 84:      */
 85:     public function subdomain($info = array())
 86:     {
 87:         $resource = new Subdomain($this->getService());
 88:         $resource->setParent($this)->populate($info);
 89:         return $resource;
 90:     }
 91: 
 92:     /**
 93:      * returns a Collection of subdomains
 94:      *
 95:      * The subdomains are all `DNS:Domain` objects that are children of
 96:      * the current domain.
 97:      *
 98:      * @param array $filter key/value pairs for query string parameters
 99:      * return \OpenCloud\Collection
100:      */
101:     public function subdomainList($filter = array())
102:     {
103:         return $this->getParent()->collection(
104:             'OpenCloud\DNS\Resource\Subdomain', null, $this
105:         );
106:     }
107: 
108:     /**
109:      * Adds a new record to the list (for multiple record creation)
110:      *
111:      * @api
112:      * @param Record $rec the record to add
113:      * @return integer the number of records
114:      */
115:     public function addRecord(Record $record)
116:     {
117:         $this->records[] = $record;
118:         return count($this->records);
119:     }
120: 
121:     /**
122:      * adds a new subdomain (for multiple subdomain creation)
123:      *
124:      * @api
125:      * @param Subdomain $subd the subdomain to add
126:      * @return integer the number of subdomains
127:      */
128:     public function addSubdomain(Subdomain $subdomain)
129:     {
130:         $this->subdomains[] = $subdomain;
131:         return count($this->subdomains);
132:     }
133: 
134:     /**
135:      * returns changes since a specified date/time
136:      *
137:      * @param string $since the date or time
138:      * @return DNS\Changes
139:      */
140:     public function changes($since = null)
141:     {   
142:         $url = $this->url('changes', isset($since) ? array('since' => $since) : array());
143:         
144:         $response = $this->getService()
145:             ->getClient()
146:             ->get($url)
147:             ->send();
148: 
149:         return Formatter::decode($response);
150:     }
151: 
152:     /**
153:      * exports the domain
154:      *
155:      * @return AsyncResponse
156:      */
157:     public function export()
158:     {
159:         return $this->getService()->asyncRequest($this->url('export'));
160:     }
161: 
162:     /**
163:      * clones the domain to the specified target domain
164:      *
165:      * @param string $newdomain the new domain to create from this domain
166:      * @param boolean $sub to clone subdomains as well
167:      * @param boolean $comments Replace occurrences of the reference domain
168:      *  name with the new domain name in comments
169:      * @param boolean $email Replace occurrences of the reference domain
170:      *  name with the new domain name in email addresses on the cloned
171:      *  (new) domain.
172:      * @param boolean $records Replace occurrences of the reference domain
173:      *  name with the new domain name in data fields (of records) on the
174:      *  cloned (new) domain. Does not affect NS records.
175:      * @return AsyncResponse
176:      */
177:     public function cloneDomain(
178:         $newdomain,
179:         $sub = true,
180:         $comments = true,
181:         $email = true,
182:         $records = true
183:     ) {
184:         $url = $this->url('clone', array(
185:             'cloneName'          => $newdomain,
186:             'cloneSubdomains'    => $sub,
187:             'modifyComment'      => $comments,
188:             'modifyEmailAddress' => $email,
189:             'modifyRecordData'   => $records
190:         ));
191:         return $this->getService()->asyncRequest($url, 'POST');
192:     }
193: 
194:     /**
195:      * handles creation of multiple records at Create()
196:      *
197:      * @api
198:      * @return \stdClass
199:      */
200:     protected function createJson()
201:     {
202:         $object = parent::createJson();
203: 
204:         // add records, if any
205:         if (count($this->records)) {
206: 
207:             $recordsObject = (object) array('records' => array());
208: 
209:             foreach ($this->records as $record) {
210:                 $recordObject = new \stdClass;
211:                 foreach($record->getCreateKeys() as $key) {
212:                     if (isset($record->$key)) {
213:                         $recordObject->$key = $record->$key;
214:                     }
215:                 }
216:                 $recordsObject->records[] = $recordObject;
217:             }
218:             $object->domains[0]->recordsList = $recordsObject;
219:         }
220: 
221:         // add subdomains, if any
222:         if (count($this->subdomains)) {
223: 
224:             $subdomainsObject = (object) array('domains' => array());
225: 
226:             foreach($this->subdomains as $subdomain) {
227:                 $subdomainObject = new \stdClass;
228:                 foreach($subdomain->getCreateKeys() as $key) {
229:                     if (isset($subdomain->$key)) {
230:                         $subdomainObject->$key = $subdomain->$key;
231:                     }
232:                 }
233:                 $subdomainsObject->domains[] = $subdomainObject;
234:             }
235:             $object->domains[0]->subdomains = $subdomainsObject;
236:         }
237: 
238:         return $object;
239:     }
240: 
241: }
242: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0