| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace common\expand\alipay;
- /**
- * 基础模型
- */
- class AlipayModel
- {
- protected $data = [];
- public function __set(string $name, $value)
- {
- $this->data[$name] = $value;
- }
- public function __get($name)
- {
- // TODO: Implement __get() method.
- return $this->data[$name] ?? null;
- }
- /**
- * @return array|mixed
- */
- public function getData()
- {
- return $this->data;
- }
- /**
- * 过滤值为空的字段
- * @return array|mixed
- */
- public function getFilterData()
- {
- return array_filter($this->data, function ($val) {
- return !empty($val);
- });
- }
- /**
- * @return array
- */
- public function toArray(): array
- {
- $data = [];
- foreach ($this->data as $key => $val) {
- if ($val instanceof AlipayModel) {
- $data[$key] = $val->getData();
- } else {
- $data[$key] = $val;
- }
- }
- return $data;
- }
- }
|