AlipayModel.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace common\expand\alipay;
  3. /**
  4. * 基础模型
  5. */
  6. class AlipayModel
  7. {
  8. protected $data = [];
  9. public function __set(string $name, $value)
  10. {
  11. $this->data[$name] = $value;
  12. }
  13. public function __get($name)
  14. {
  15. // TODO: Implement __get() method.
  16. return $this->data[$name] ?? null;
  17. }
  18. /**
  19. * @return array|mixed
  20. */
  21. public function getData()
  22. {
  23. return $this->data;
  24. }
  25. /**
  26. * 过滤值为空的字段
  27. * @return array|mixed
  28. */
  29. public function getFilterData()
  30. {
  31. return array_filter($this->data, function ($val) {
  32. return !empty($val);
  33. });
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function toArray(): array
  39. {
  40. $data = [];
  41. foreach ($this->data as $key => $val) {
  42. if ($val instanceof AlipayModel) {
  43. $data[$key] = $val->getData();
  44. } else {
  45. $data[$key] = $val;
  46. }
  47. }
  48. return $data;
  49. }
  50. }