1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
6: use \Saklient\Cloud\Client;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
8: use \Saklient\Cloud\Resources\Resource;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Icon.php";
10: use \Saklient\Cloud\Resources\Icon;
11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/FtpInfo.php";
12: use \Saklient\Cloud\Resources\FtpInfo;
13: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EScope.php";
14: use \Saklient\Cloud\Enums\EScope;
15: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
16: use \Saklient\Errors\SaklientException;
17: require_once __DIR__ . "/../../../Saklient/Util.php";
18: use \Saklient\Util;
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: class IsoImage extends Resource {
36:
37: 38: 39: 40: 41: 42: 43:
44: protected $m_id;
45:
46: 47: 48: 49: 50: 51: 52:
53: protected $m_scope;
54:
55: 56: 57: 58: 59: 60: 61:
62: protected $m_name;
63:
64: 65: 66: 67: 68: 69: 70:
71: protected $m_description;
72:
73: 74: 75: 76: 77: 78: 79:
80: protected $m_tags;
81:
82: 83: 84: 85: 86: 87: 88:
89: protected $m_icon;
90:
91: 92: 93: 94: 95: 96: 97:
98: protected $m_displayOrder;
99:
100: 101: 102: 103: 104: 105: 106:
107: protected $m_sizeMib;
108:
109: 110: 111: 112: 113: 114: 115:
116: protected $m_serviceClass;
117:
118: 119: 120: 121: 122: 123:
124: protected function _apiPath()
125: {
126: return "/cdrom";
127: }
128:
129: 130: 131: 132: 133: 134:
135: protected function _rootKey()
136: {
137: return "CDROM";
138: }
139:
140: 141: 142: 143: 144: 145:
146: protected function _rootKeyM()
147: {
148: return "CDROMs";
149: }
150:
151: 152: 153: 154: 155: 156:
157: public function _className()
158: {
159: return "IsoImage";
160: }
161:
162: 163: 164: 165: 166: 167:
168: public function _id()
169: {
170: return $this->get_id();
171: }
172:
173: 174: 175: 176: 177: 178:
179: public function save()
180: {
181: return $this->_save();
182: }
183:
184: 185: 186: 187: 188: 189:
190: public function reload()
191: {
192: return $this->_reload();
193: }
194:
195: 196: 197: 198: 199: 200: 201:
202: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
203: {
204: parent::__construct($client);
205: Util::validateArgCount(func_num_args(), 2);
206: Util::validateType($client, "\\Saklient\\Cloud\\Client");
207: Util::validateType($wrapped, "boolean");
208: $this->apiDeserialize($obj, $wrapped);
209: }
210:
211: 212: 213: 214: 215: 216: 217: 218:
219: protected function _onAfterApiDeserialize($r, $root)
220: {
221: Util::validateArgCount(func_num_args(), 2);
222: if ($root == null) {
223: return;
224: }
225: if (array_key_exists("FTPServer", (array)($root))) {
226: $ftp = $root->{"FTPServer"};
227: if ($ftp != null) {
228: $this->_ftpInfo = new FtpInfo($ftp);
229: }
230: }
231: }
232:
233: 234: 235: 236: 237:
238: protected function get_sizeGib()
239: {
240: $sizeMib = $this->get_sizeMib();
241: return $sizeMib == null ? null : $sizeMib >> 10;
242: }
243:
244: 245: 246: 247: 248: 249:
250: protected function set_sizeGib($sizeGib)
251: {
252: Util::validateArgCount(func_num_args(), 1);
253: Util::validateType($sizeGib, "int");
254: $this->set_sizeMib($sizeGib == null ? null : $sizeGib * 1024);
255: return $sizeGib;
256: }
257:
258:
259:
260: 261: 262: 263: 264: 265:
266: protected $_ftpInfo;
267:
268: 269: 270: 271: 272:
273: public function get_ftpInfo()
274: {
275: return $this->_ftpInfo;
276: }
277:
278:
279:
280: 281: 282: 283: 284: 285: 286: 287: 288:
289: public function openFtp($reset=false)
290: {
291: Util::validateType($reset, "boolean");
292: $path = $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ftp";
293: $q = (object)[];
294: Util::setByPath($q, "ChangePassword", $reset);
295: $result = $this->_client->request("PUT", $path, $q);
296: $this->_onAfterApiDeserialize(null, $result);
297: return $this;
298: }
299:
300: 301: 302: 303: 304: 305:
306: public function closeFtp()
307: {
308: $path = $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ftp";
309: $this->_client->request("DELETE", $path);
310: $this->_ftpInfo = null;
311: return $this;
312: }
313:
314: 315: 316: 317: 318:
319: private $n_id = false;
320:
321: 322: 323: 324: 325: 326: 327:
328: private function get_id()
329: {
330: return $this->m_id;
331: }
332:
333:
334:
335: 336: 337: 338: 339:
340: private $n_scope = false;
341:
342: 343: 344: 345: 346: 347: 348:
349: private function get_scope()
350: {
351: return $this->m_scope;
352: }
353:
354: 355: 356: 357: 358: 359: 360: 361:
362: private function set_scope($v)
363: {
364: Util::validateArgCount(func_num_args(), 1);
365: Util::validateType($v, "string");
366: $this->m_scope = $v;
367: $this->n_scope = true;
368: return $this->m_scope;
369: }
370:
371:
372:
373: 374: 375: 376: 377:
378: private $n_name = false;
379:
380: 381: 382: 383: 384: 385: 386:
387: private function get_name()
388: {
389: return $this->m_name;
390: }
391:
392: 393: 394: 395: 396: 397: 398: 399:
400: private function set_name($v)
401: {
402: Util::validateArgCount(func_num_args(), 1);
403: Util::validateType($v, "string");
404: $this->m_name = $v;
405: $this->n_name = true;
406: return $this->m_name;
407: }
408:
409:
410:
411: 412: 413: 414: 415:
416: private $n_description = false;
417:
418: 419: 420: 421: 422: 423: 424:
425: private function get_description()
426: {
427: return $this->m_description;
428: }
429:
430: 431: 432: 433: 434: 435: 436: 437:
438: private function set_description($v)
439: {
440: Util::validateArgCount(func_num_args(), 1);
441: Util::validateType($v, "string");
442: $this->m_description = $v;
443: $this->n_description = true;
444: return $this->m_description;
445: }
446:
447:
448:
449: 450: 451: 452: 453:
454: private $n_tags = false;
455:
456: 457: 458: 459: 460: 461: 462:
463: private function get_tags()
464: {
465: $this->n_tags = true;
466: return $this->m_tags;
467: }
468:
469: 470: 471: 472: 473: 474: 475: 476:
477: private function set_tags($v)
478: {
479: Util::validateArgCount(func_num_args(), 1);
480: Util::validateType($v, "\\ArrayObject");
481: if (is_array($v)) $v = Client::array2ArrayObject($v);
482: $this->m_tags = $v;
483: $this->n_tags = true;
484: return $this->m_tags;
485: }
486:
487:
488:
489: 490: 491: 492: 493:
494: private $n_icon = false;
495:
496: 497: 498: 499: 500: 501: 502:
503: private function get_icon()
504: {
505: return $this->m_icon;
506: }
507:
508: 509: 510: 511: 512: 513: 514: 515:
516: private function set_icon(\Saklient\Cloud\Resources\Icon $v=null)
517: {
518: Util::validateArgCount(func_num_args(), 1);
519: Util::validateType($v, "\\Saklient\\Cloud\\Resources\\Icon");
520: $this->m_icon = $v;
521: $this->n_icon = true;
522: return $this->m_icon;
523: }
524:
525:
526:
527: 528: 529: 530: 531:
532: private $n_displayOrder = false;
533:
534: 535: 536: 537: 538: 539: 540:
541: private function get_displayOrder()
542: {
543: return $this->m_displayOrder;
544: }
545:
546: 547: 548: 549: 550: 551: 552: 553:
554: private function set_displayOrder($v)
555: {
556: Util::validateArgCount(func_num_args(), 1);
557: Util::validateType($v, "int");
558: $this->m_displayOrder = $v;
559: $this->n_displayOrder = true;
560: return $this->m_displayOrder;
561: }
562:
563:
564:
565: 566: 567: 568: 569:
570: private $n_sizeMib = false;
571:
572: 573: 574: 575: 576: 577: 578:
579: private function get_sizeMib()
580: {
581: return $this->m_sizeMib;
582: }
583:
584: 585: 586: 587: 588: 589: 590: 591:
592: private function set_sizeMib($v)
593: {
594: Util::validateArgCount(func_num_args(), 1);
595: Util::validateType($v, "int");
596: if (!$this->isNew) {
597: throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\IsoImage#sizeMib");
598: }
599: $this->m_sizeMib = $v;
600: $this->n_sizeMib = true;
601: return $this->m_sizeMib;
602: }
603:
604:
605:
606: 607: 608: 609: 610:
611: private $n_serviceClass = false;
612:
613: 614: 615: 616: 617: 618: 619:
620: private function get_serviceClass()
621: {
622: return $this->m_serviceClass;
623: }
624:
625:
626:
627: 628: 629: 630: 631: 632: 633:
634: protected function apiDeserializeImpl($r)
635: {
636: Util::validateArgCount(func_num_args(), 1);
637: $this->isNew = $r == null;
638: if ($this->isNew) {
639: $r = (object)[];
640: }
641: $this->isIncomplete = false;
642: if (Util::existsPath($r, "ID")) {
643: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
644: }
645: else {
646: $this->m_id = null;
647: $this->isIncomplete = true;
648: }
649: $this->n_id = false;
650: if (Util::existsPath($r, "Scope")) {
651: $this->m_scope = Util::getByPath($r, "Scope") == null ? null : "" . Util::getByPath($r, "Scope");
652: }
653: else {
654: $this->m_scope = null;
655: $this->isIncomplete = true;
656: }
657: $this->n_scope = false;
658: if (Util::existsPath($r, "Name")) {
659: $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
660: }
661: else {
662: $this->m_name = null;
663: $this->isIncomplete = true;
664: }
665: $this->n_name = false;
666: if (Util::existsPath($r, "Description")) {
667: $this->m_description = Util::getByPath($r, "Description") == null ? null : "" . Util::getByPath($r, "Description");
668: }
669: else {
670: $this->m_description = null;
671: $this->isIncomplete = true;
672: }
673: $this->n_description = false;
674: if (Util::existsPath($r, "Tags")) {
675: if (Util::getByPath($r, "Tags") == null) {
676: $this->m_tags = new \ArrayObject([]);
677: }
678: else {
679: $this->m_tags = new \ArrayObject([]);
680: foreach (Util::getByPath($r, "Tags") as $t) {
681: $v1 = null;
682: $v1 = $t == null ? null : "" . $t;
683: $this->m_tags->append($v1);
684: }
685: }
686: }
687: else {
688: $this->m_tags = null;
689: $this->isIncomplete = true;
690: }
691: $this->n_tags = false;
692: if (Util::existsPath($r, "Icon")) {
693: $this->m_icon = Util::getByPath($r, "Icon") == null ? null : new Icon($this->_client, Util::getByPath($r, "Icon"));
694: }
695: else {
696: $this->m_icon = null;
697: $this->isIncomplete = true;
698: }
699: $this->n_icon = false;
700: if (Util::existsPath($r, "DisplayOrder")) {
701: $this->m_displayOrder = Util::getByPath($r, "DisplayOrder") == null ? null : intval("" . Util::getByPath($r, "DisplayOrder"));
702: }
703: else {
704: $this->m_displayOrder = null;
705: $this->isIncomplete = true;
706: }
707: $this->n_displayOrder = false;
708: if (Util::existsPath($r, "SizeMB")) {
709: $this->m_sizeMib = Util::getByPath($r, "SizeMB") == null ? null : intval("" . Util::getByPath($r, "SizeMB"));
710: }
711: else {
712: $this->m_sizeMib = null;
713: $this->isIncomplete = true;
714: }
715: $this->n_sizeMib = false;
716: if (Util::existsPath($r, "ServiceClass")) {
717: $this->m_serviceClass = Util::getByPath($r, "ServiceClass") == null ? null : "" . Util::getByPath($r, "ServiceClass");
718: }
719: else {
720: $this->m_serviceClass = null;
721: $this->isIncomplete = true;
722: }
723: $this->n_serviceClass = false;
724: }
725:
726: 727: 728: 729: 730: 731:
732: protected function apiSerializeImpl($withClean=false)
733: {
734: Util::validateType($withClean, "boolean");
735: $missing = new \ArrayObject([]);
736: $ret = (object)[];
737: if ($withClean || $this->n_id) {
738: Util::setByPath($ret, "ID", $this->m_id);
739: }
740: if ($withClean || $this->n_scope) {
741: Util::setByPath($ret, "Scope", $this->m_scope);
742: }
743: if ($withClean || $this->n_name) {
744: Util::setByPath($ret, "Name", $this->m_name);
745: }
746: else {
747: if ($this->isNew) {
748: $missing->append("name");
749: }
750: }
751: if ($withClean || $this->n_description) {
752: Util::setByPath($ret, "Description", $this->m_description);
753: }
754: if ($withClean || $this->n_tags) {
755: Util::setByPath($ret, "Tags", new \ArrayObject([]));
756: foreach ($this->m_tags as $r1) {
757: $v = null;
758: $v = $r1;
759: $ret->{"Tags"}->append($v);
760: }
761: }
762: if ($withClean || $this->n_icon) {
763: Util::setByPath($ret, "Icon", $withClean ? ($this->m_icon == null ? null : $this->m_icon->apiSerialize($withClean)) : ($this->m_icon == null ? (object)['ID' => "0"] : $this->m_icon->apiSerializeID()));
764: }
765: if ($withClean || $this->n_displayOrder) {
766: Util::setByPath($ret, "DisplayOrder", $this->m_displayOrder);
767: }
768: if ($withClean || $this->n_sizeMib) {
769: Util::setByPath($ret, "SizeMB", $this->m_sizeMib);
770: }
771: else {
772: if ($this->isNew) {
773: $missing->append("sizeMib");
774: }
775: }
776: if ($withClean || $this->n_serviceClass) {
777: Util::setByPath($ret, "ServiceClass", $this->m_serviceClass);
778: }
779: if ($missing->count() > 0) {
780: throw new SaklientException("required_field", "Required fields must be set before the IsoImage creation: " . implode(", ", (array)($missing)));
781: }
782: return $ret;
783: }
784:
785: 786: 787:
788: public function __get($key) {
789: switch ($key) {
790: case "sizeGib": return $this->get_sizeGib();
791: case "ftpInfo": return $this->get_ftpInfo();
792: case "id": return $this->get_id();
793: case "scope": return $this->get_scope();
794: case "name": return $this->get_name();
795: case "description": return $this->get_description();
796: case "tags": return $this->get_tags();
797: case "icon": return $this->get_icon();
798: case "displayOrder": return $this->get_displayOrder();
799: case "sizeMib": return $this->get_sizeMib();
800: case "serviceClass": return $this->get_serviceClass();
801: default: return parent::__get($key);
802: }
803: }
804:
805: 806: 807:
808: public function __set($key, $v) {
809: switch ($key) {
810: case "sizeGib": return $this->set_sizeGib($v);
811: case "scope": return $this->set_scope($v);
812: case "name": return $this->set_name($v);
813: case "description": return $this->set_description($v);
814: case "tags": return $this->set_tags($v);
815: case "icon": return $this->set_icon($v);
816: case "displayOrder": return $this->set_displayOrder($v);
817: case "sizeMib": return $this->set_sizeMib($v);
818: default: return parent::__set($key, $v);
819: }
820: }
821:
822: }
823:
824: