1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace OpenCloud\DNS;
13:
14: 15: 16: 17: 18: 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 ;
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: 54: 55: 56: 57: 58: 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: 70: 71: 72: 73:
74: public function recordList($filter = array())
75: {
76: return $this->getParent()->collection('OpenCloud\DNS\Record', null, $this, $filter);
77: }
78:
79: 80: 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: 93: 94: 95: 96: 97: 98: 99:
100: public function subdomainList($filter = array())
101: {
102: return $this->getParent()->collection('OpenCloud\DNS\Subdomain', null, $this);
103: }
104:
105: 106: 107: 108: 109: 110: 111:
112: public function addRecord(Record $record)
113: {
114: $this->records[] = $record;
115: return count($this->records);
116: }
117:
118: 119: 120: 121: 122: 123: 124:
125: public function addSubdomain(Subdomain $subdomain)
126: {
127: $this->subdomains[] = $subdomain;
128: return count($this->subdomains);
129: }
130:
131: 132: 133: 134: 135: 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: 145: 146: 147:
148: public function export()
149: {
150: return $this->getService()->asyncRequest($this->url('export'));
151: }
152:
153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 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: 187: 188: 189: 190:
191: protected function createJson()
192: {
193: $object = parent::createJson();
194:
195:
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:
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: