| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace addons\WangDianTong\common\expand\sdk\wangdian;
- class Model
- {
- /**
- * @var array
- */
- protected $data = [];
- protected $sort_key = [];
- protected $ret_data = [];
- protected $sort_reset_key = true;
- public function __set($name, $value)
- {
- $this->data[$name] = $value;
- }
- public function __get($name)
- {
- return $this->data[$name] ?? null;
- }
- public function __isset($name)
- {
- return isset($this->data[$name]);
- }
- /**
- * @return array
- */
- public function getData(): array
- {
- return $this->data;
- }
- /**
- * @return array
- */
- public function toArray(): array
- {
- foreach ($this->data as $key => $value) {
- if ($value instanceof Model) {
- $this->ret_data[$key] = $value->toArray();
- } else {
- $this->ret_data[$key] = $value;
- }
- }
- return $this->ret_data;
- }
- /**
- * @return array
- * @throws \Exception
- */
- public function sort(): array
- {
- $data = [];
- foreach ($this->sort_key as $item) {
- if (!empty($this->ret_data[$item])) {
- if (!$this->sort_reset_key) {
- $data[$item] = $this->ret_data[$item];
- } else {
- $data[] = $this->ret_data[$item];
- }
- }
- }
- return $data;
- }
- }
|