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/Enums/EScope.php";
12: use \Saklient\Cloud\Enums\EScope;
13: require_once __DIR__ . "/../../../Saklient/Util.php";
14: use \Saklient\Util;
15:
16: 17: 18: 19: 20: 21: 22:
23: class Region extends Resource {
24:
25: 26: 27: 28: 29: 30: 31:
32: protected $m_id;
33:
34: 35: 36: 37: 38: 39: 40:
41: protected $m_name;
42:
43: 44: 45: 46: 47: 48: 49:
50: protected $m_description;
51:
52: 53: 54: 55: 56: 57:
58: protected function _apiPath()
59: {
60: return "/region";
61: }
62:
63: 64: 65: 66: 67: 68:
69: protected function _rootKey()
70: {
71: return "Region";
72: }
73:
74: 75: 76: 77: 78: 79:
80: protected function _rootKeyM()
81: {
82: return "Regions";
83: }
84:
85: 86: 87: 88: 89: 90:
91: public function _className()
92: {
93: return "Region";
94: }
95:
96: 97: 98: 99: 100: 101:
102: public function _id()
103: {
104: return $this->get_id();
105: }
106:
107: 108: 109: 110: 111: 112: 113:
114: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
115: {
116: parent::__construct($client);
117: Util::validateArgCount(func_num_args(), 2);
118: Util::validateType($client, "\\Saklient\\Cloud\\Client");
119: Util::validateType($wrapped, "boolean");
120: $this->apiDeserialize($obj, $wrapped);
121: }
122:
123: 124: 125: 126: 127:
128: private $n_id = false;
129:
130: 131: 132: 133: 134: 135: 136:
137: private function get_id()
138: {
139: return $this->m_id;
140: }
141:
142:
143:
144: 145: 146: 147: 148:
149: private $n_name = false;
150:
151: 152: 153: 154: 155: 156: 157:
158: private function get_name()
159: {
160: return $this->m_name;
161: }
162:
163: 164: 165: 166: 167: 168: 169: 170:
171: private function set_name($v)
172: {
173: Util::validateArgCount(func_num_args(), 1);
174: Util::validateType($v, "string");
175: $this->m_name = $v;
176: $this->n_name = true;
177: return $this->m_name;
178: }
179:
180:
181:
182: 183: 184: 185: 186:
187: private $n_description = false;
188:
189: 190: 191: 192: 193: 194: 195:
196: private function get_description()
197: {
198: return $this->m_description;
199: }
200:
201: 202: 203: 204: 205: 206: 207: 208:
209: private function set_description($v)
210: {
211: Util::validateArgCount(func_num_args(), 1);
212: Util::validateType($v, "string");
213: $this->m_description = $v;
214: $this->n_description = true;
215: return $this->m_description;
216: }
217:
218:
219:
220: 221: 222: 223: 224: 225: 226:
227: protected function apiDeserializeImpl($r)
228: {
229: Util::validateArgCount(func_num_args(), 1);
230: $this->isNew = $r == null;
231: if ($this->isNew) {
232: $r = (object)[];
233: }
234: $this->isIncomplete = false;
235: if (Util::existsPath($r, "ID")) {
236: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
237: }
238: else {
239: $this->m_id = null;
240: $this->isIncomplete = true;
241: }
242: $this->n_id = false;
243: if (Util::existsPath($r, "Name")) {
244: $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
245: }
246: else {
247: $this->m_name = null;
248: $this->isIncomplete = true;
249: }
250: $this->n_name = false;
251: if (Util::existsPath($r, "Description")) {
252: $this->m_description = Util::getByPath($r, "Description") == null ? null : "" . Util::getByPath($r, "Description");
253: }
254: else {
255: $this->m_description = null;
256: $this->isIncomplete = true;
257: }
258: $this->n_description = false;
259: }
260:
261: 262: 263: 264: 265: 266:
267: protected function apiSerializeImpl($withClean=false)
268: {
269: Util::validateType($withClean, "boolean");
270: $missing = new \ArrayObject([]);
271: $ret = (object)[];
272: if ($withClean || $this->n_id) {
273: Util::setByPath($ret, "ID", $this->m_id);
274: }
275: if ($withClean || $this->n_name) {
276: Util::setByPath($ret, "Name", $this->m_name);
277: }
278: else {
279: if ($this->isNew) {
280: $missing->append("name");
281: }
282: }
283: if ($withClean || $this->n_description) {
284: Util::setByPath($ret, "Description", $this->m_description);
285: }
286: if ($missing->count() > 0) {
287: throw new SaklientException("required_field", "Required fields must be set before the Region creation: " . implode(", ", (array)($missing)));
288: }
289: return $ret;
290: }
291:
292: 293: 294:
295: public function __get($key) {
296: switch ($key) {
297: case "id": return $this->get_id();
298: case "name": return $this->get_name();
299: case "description": return $this->get_description();
300: default: return parent::__get($key);
301: }
302: }
303:
304: 305: 306:
307: public function __set($key, $v) {
308: switch ($key) {
309: case "name": return $this->set_name($v);
310: case "description": return $this->set_description($v);
311: default: return parent::__set($key, $v);
312: }
313: }
314:
315: }
316:
317: