1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace OpenCloud\DNS;
13:
14: use OpenCloud\Common\Lang;
15: use OpenCloud\Common\Exceptions;
16:
17: 18: 19: 20: 21: 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: 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: 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: 61: 62: 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: 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: 85: 86: 87: 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:
103: $response = $this->getService()->request($url, 'DELETE');
104:
105:
106: return new AsyncResponse($this->getService(), $response->HttpBody());
107: }
108:
109: 110: 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: 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: