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