Customer.php 677 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace DNB;
  3. class Customer extends AbstractPostSerializable implements PostSerializableInterface {
  4. public function __construct(
  5. private string $name,
  6. private ?string $email,
  7. private string $mobilePhone,
  8. private ?string $zipCode = null,
  9. private ?string $comment = null,
  10. ) {}
  11. public function toPostParams(): array {
  12. $arr = [];
  13. foreach (static::getClassVars() as $key)
  14. if (!is_null($this->{$key}))
  15. $arr[$key] = $this->{$key};
  16. return $arr;
  17. }
  18. protected static function getClassVars(): array {
  19. return array_keys(get_class_vars(__CLASS__));
  20. }
  21. }