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/LicenseInfo.php";
12: use \Saklient\Cloud\Resources\LicenseInfo;
13: require_once __DIR__ . "/../../../Saklient/Util.php";
14: use \Saklient\Util;
15:
16: 17: 18: 19: 20: 21: 22:
23: class License 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_info;
51:
52: 53: 54: 55: 56: 57:
58: protected function _apiPath()
59: {
60: return "/license";
61: }
62:
63: 64: 65: 66: 67: 68:
69: protected function _rootKey()
70: {
71: return "License";
72: }
73:
74: 75: 76: 77: 78: 79:
80: protected function _rootKeyM()
81: {
82: return "Licenses";
83: }
84:
85: 86: 87: 88: 89: 90:
91: public function _className()
92: {
93: return "License";
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: public function save()
114: {
115: return $this->_save();
116: }
117:
118: 119: 120: 121: 122: 123:
124: public function reload()
125: {
126: return $this->_reload();
127: }
128:
129: 130: 131: 132: 133: 134: 135:
136: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
137: {
138: parent::__construct($client);
139: Util::validateArgCount(func_num_args(), 2);
140: Util::validateType($client, "\\Saklient\\Cloud\\Client");
141: Util::validateType($wrapped, "boolean");
142: $this->apiDeserialize($obj, $wrapped);
143: }
144:
145: 146: 147: 148: 149:
150: private $n_id = false;
151:
152: 153: 154: 155: 156: 157: 158:
159: private function get_id()
160: {
161: return $this->m_id;
162: }
163:
164:
165:
166: 167: 168: 169: 170:
171: private $n_name = false;
172:
173: 174: 175: 176: 177: 178: 179:
180: private function get_name()
181: {
182: return $this->m_name;
183: }
184:
185: 186: 187: 188: 189: 190: 191: 192:
193: private function set_name($v)
194: {
195: Util::validateArgCount(func_num_args(), 1);
196: Util::validateType($v, "string");
197: $this->m_name = $v;
198: $this->n_name = true;
199: return $this->m_name;
200: }
201:
202:
203:
204: 205: 206: 207: 208:
209: private $n_info = false;
210:
211: 212: 213: 214: 215: 216: 217:
218: private function get_info()
219: {
220: return $this->m_info;
221: }
222:
223: 224: 225: 226: 227: 228: 229: 230:
231: private function set_info(\Saklient\Cloud\Resources\LicenseInfo $v)
232: {
233: Util::validateArgCount(func_num_args(), 1);
234: Util::validateType($v, "\\Saklient\\Cloud\\Resources\\LicenseInfo");
235: if (!$this->isNew) {
236: throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\License#info");
237: }
238: $this->m_info = $v;
239: $this->n_info = true;
240: return $this->m_info;
241: }
242:
243:
244:
245: 246: 247: 248: 249: 250: 251:
252: protected function apiDeserializeImpl($r)
253: {
254: Util::validateArgCount(func_num_args(), 1);
255: $this->isNew = $r == null;
256: if ($this->isNew) {
257: $r = (object)[];
258: }
259: $this->isIncomplete = false;
260: if (Util::existsPath($r, "ID")) {
261: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
262: }
263: else {
264: $this->m_id = null;
265: $this->isIncomplete = true;
266: }
267: $this->n_id = false;
268: if (Util::existsPath($r, "Name")) {
269: $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
270: }
271: else {
272: $this->m_name = null;
273: $this->isIncomplete = true;
274: }
275: $this->n_name = false;
276: if (Util::existsPath($r, "LicenseInfo")) {
277: $this->m_info = Util::getByPath($r, "LicenseInfo") == null ? null : new LicenseInfo($this->_client, Util::getByPath($r, "LicenseInfo"));
278: }
279: else {
280: $this->m_info = null;
281: $this->isIncomplete = true;
282: }
283: $this->n_info = false;
284: }
285:
286: 287: 288: 289: 290: 291:
292: protected function apiSerializeImpl($withClean=false)
293: {
294: Util::validateType($withClean, "boolean");
295: $missing = new \ArrayObject([]);
296: $ret = (object)[];
297: if ($withClean || $this->n_id) {
298: Util::setByPath($ret, "ID", $this->m_id);
299: }
300: if ($withClean || $this->n_name) {
301: Util::setByPath($ret, "Name", $this->m_name);
302: }
303: else {
304: if ($this->isNew) {
305: $missing->append("name");
306: }
307: }
308: if ($withClean || $this->n_info) {
309: Util::setByPath($ret, "LicenseInfo", $withClean ? ($this->m_info == null ? null : $this->m_info->apiSerialize($withClean)) : ($this->m_info == null ? (object)['ID' => "0"] : $this->m_info->apiSerializeID()));
310: }
311: else {
312: if ($this->isNew) {
313: $missing->append("info");
314: }
315: }
316: if ($missing->count() > 0) {
317: throw new SaklientException("required_field", "Required fields must be set before the License creation: " . implode(", ", (array)($missing)));
318: }
319: return $ret;
320: }
321:
322: 323: 324:
325: public function __get($key) {
326: switch ($key) {
327: case "id": return $this->get_id();
328: case "name": return $this->get_name();
329: case "info": return $this->get_info();
330: default: return parent::__get($key);
331: }
332: }
333:
334: 335: 336:
337: public function __set($key, $v) {
338: switch ($key) {
339: case "name": return $this->set_name($v);
340: case "info": return $this->set_info($v);
341: default: return parent::__set($key, $v);
342: }
343: }
344:
345: }
346:
347: