1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace OpenCloud\DNS\Resource;
12:
13: use OpenCloud\Common\Http\Message\Formatter;
14:
15: 16: 17: 18: 19: 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 ;
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: 55: 56: 57: 58: 59: 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: 70: 71: 72: 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: 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: 94: 95: 96: 97: 98: 99: 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: 110: 111: 112: 113: 114:
115: public function addRecord(Record $record)
116: {
117: $this->records[] = $record;
118: return count($this->records);
119: }
120:
121: 122: 123: 124: 125: 126: 127:
128: public function addSubdomain(Subdomain $subdomain)
129: {
130: $this->subdomains[] = $subdomain;
131: return count($this->subdomains);
132: }
133:
134: 135: 136: 137: 138: 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: 154: 155: 156:
157: public function export()
158: {
159: return $this->getService()->asyncRequest($this->url('export'));
160: }
161:
162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 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: 196: 197: 198: 199:
200: protected function createJson()
201: {
202: $object = parent::createJson();
203:
204:
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:
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: