Export.php 859 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * This file is part of the Klarna KP module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Kp\Model\Api;
  11. /**
  12. * Trait Export
  13. *
  14. * @package Klarna\Kp\Model\Api
  15. */
  16. trait Export
  17. {
  18. /**
  19. * Exportable class fields
  20. *
  21. * @var array
  22. */
  23. public $exports = [];
  24. /**
  25. * Generate array object needed for API call
  26. *
  27. * @return array
  28. */
  29. public function toArray()
  30. {
  31. $data = [];
  32. if (!is_array($this->exports)) {
  33. return $data;
  34. }
  35. foreach ($this->exports as $export) {
  36. if ($this->$export !== null) {
  37. $data[$export] = $this->$export;
  38. }
  39. }
  40. return $data;
  41. }
  42. }