1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
6: use \Saklient\Errors\SaklientException;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
8: use \Saklient\Cloud\Client;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
10: use \Saklient\Cloud\Resources\Resource;
11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Region.php";
12: use \Saklient\Cloud\Resources\Region;
13: require_once __DIR__ . "/../../../Saklient/Util.php";
14: use \Saklient\Util;
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class Bridge extends Resource {
25:
26: 27: 28: 29: 30: 31: 32:
33: protected $m_id;
34:
35: 36: 37: 38: 39: 40: 41:
42: protected $m_name;
43:
44: 45: 46: 47: 48: 49: 50:
51: protected $m_description;
52:
53: 54: 55: 56: 57: 58: 59:
60: protected $m_region;
61:
62: 63: 64: 65: 66: 67:
68: protected function _apiPath()
69: {
70: return "/bridge";
71: }
72:
73: 74: 75: 76: 77: 78:
79: protected function _rootKey()
80: {
81: return "Bridge";
82: }
83:
84: 85: 86: 87: 88: 89:
90: protected function _rootKeyM()
91: {
92: return "Bridges";
93: }
94:
95: 96: 97: 98: 99: 100:
101: public function _className()
102: {
103: return "Bridge";
104: }
105:
106: 107: 108: 109: 110: 111:
112: public function _id()
113: {
114: return $this->get_id();
115: }
116:
117: 118: 119: 120: 121: 122:
123: public function save()
124: {
125: return $this->_save();
126: }
127:
128: 129: 130: 131: 132: 133:
134: public function reload()
135: {
136: return $this->_reload();
137: }
138:
139: 140: 141: 142: 143: 144: 145:
146: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
147: {
148: parent::__construct($client);
149: Util::validateArgCount(func_num_args(), 2);
150: Util::validateType($client, "\\Saklient\\Cloud\\Client");
151: Util::validateType($wrapped, "boolean");
152: $this->apiDeserialize($obj, $wrapped);
153: }
154:
155: 156: 157: 158: 159:
160: private $n_id = false;
161:
162: 163: 164: 165: 166: 167: 168:
169: private function get_id()
170: {
171: return $this->m_id;
172: }
173:
174:
175:
176: 177: 178: 179: 180:
181: private $n_name = false;
182:
183: 184: 185: 186: 187: 188: 189:
190: private function get_name()
191: {
192: return $this->m_name;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: private function set_name($v)
204: {
205: Util::validateArgCount(func_num_args(), 1);
206: Util::validateType($v, "string");
207: $this->m_name = $v;
208: $this->n_name = true;
209: return $this->m_name;
210: }
211:
212:
213:
214: 215: 216: 217: 218:
219: private $n_description = false;
220:
221: 222: 223: 224: 225: 226: 227:
228: private function get_description()
229: {
230: return $this->m_description;
231: }
232:
233: 234: 235: 236: 237: 238: 239: 240:
241: private function set_description($v)
242: {
243: Util::validateArgCount(func_num_args(), 1);
244: Util::validateType($v, "string");
245: $this->m_description = $v;
246: $this->n_description = true;
247: return $this->m_description;
248: }
249:
250:
251:
252: 253: 254: 255: 256:
257: private $n_region = false;
258:
259: 260: 261: 262: 263: 264: 265:
266: private function get_region()
267: {
268: return $this->m_region;
269: }
270:
271: 272: 273: 274: 275: 276: 277: 278:
279: private function set_region(\Saklient\Cloud\Resources\Region $v=null)
280: {
281: Util::validateArgCount(func_num_args(), 1);
282: Util::validateType($v, "\\Saklient\\Cloud\\Resources\\Region");
283: if (!$this->isNew) {
284: throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\Bridge#region");
285: }
286: $this->m_region = $v;
287: $this->n_region = true;
288: return $this->m_region;
289: }
290:
291:
292:
293: 294: 295: 296: 297: 298: 299:
300: protected function apiDeserializeImpl($r)
301: {
302: Util::validateArgCount(func_num_args(), 1);
303: $this->isNew = $r == null;
304: if ($this->isNew) {
305: $r = (object)[];
306: }
307: $this->isIncomplete = false;
308: if (Util::existsPath($r, "ID")) {
309: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
310: }
311: else {
312: $this->m_id = null;
313: $this->isIncomplete = true;
314: }
315: $this->n_id = false;
316: if (Util::existsPath($r, "Name")) {
317: $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
318: }
319: else {
320: $this->m_name = null;
321: $this->isIncomplete = true;
322: }
323: $this->n_name = false;
324: if (Util::existsPath($r, "Description")) {
325: $this->m_description = Util::getByPath($r, "Description") == null ? null : "" . Util::getByPath($r, "Description");
326: }
327: else {
328: $this->m_description = null;
329: $this->isIncomplete = true;
330: }
331: $this->n_description = false;
332: if (Util::existsPath($r, "Region")) {
333: $this->m_region = Util::getByPath($r, "Region") == null ? null : new Region($this->_client, Util::getByPath($r, "Region"));
334: }
335: else {
336: $this->m_region = null;
337: $this->isIncomplete = true;
338: }
339: $this->n_region = false;
340: }
341:
342: 343: 344: 345: 346: 347:
348: protected function apiSerializeImpl($withClean=false)
349: {
350: Util::validateType($withClean, "boolean");
351: $missing = new \ArrayObject([]);
352: $ret = (object)[];
353: if ($withClean || $this->n_id) {
354: Util::setByPath($ret, "ID", $this->m_id);
355: }
356: if ($withClean || $this->n_name) {
357: Util::setByPath($ret, "Name", $this->m_name);
358: }
359: else {
360: if ($this->isNew) {
361: $missing->append("name");
362: }
363: }
364: if ($withClean || $this->n_description) {
365: Util::setByPath($ret, "Description", $this->m_description);
366: }
367: if ($withClean || $this->n_region) {
368: Util::setByPath($ret, "Region", $withClean ? ($this->m_region == null ? null : $this->m_region->apiSerialize($withClean)) : ($this->m_region == null ? (object)['ID' => "0"] : $this->m_region->apiSerializeID()));
369: }
370: else {
371: if ($this->isNew) {
372: $missing->append("region");
373: }
374: }
375: if ($missing->count() > 0) {
376: throw new SaklientException("required_field", "Required fields must be set before the Bridge creation: " . implode(", ", (array)($missing)));
377: }
378: return $ret;
379: }
380:
381: 382: 383:
384: public function __get($key) {
385: switch ($key) {
386: case "id": return $this->get_id();
387: case "name": return $this->get_name();
388: case "description": return $this->get_description();
389: case "region": return $this->get_region();
390: default: return parent::__get($key);
391: }
392: }
393:
394: 395: 396:
397: public function __set($key, $v) {
398: switch ($key) {
399: case "name": return $this->set_name($v);
400: case "description": return $this->set_description($v);
401: case "region": return $this->set_region($v);
402: default: return parent::__set($key, $v);
403: }
404: }
405:
406: }
407:
408: