Address.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * File: Address.php
  4. * Category: -
  5. * Author: M. Goldenbaum
  6. * Created: 01.01.21 21:17
  7. * Updated: -
  8. *
  9. * Description:
  10. * -
  11. */
  12. namespace Webklex\PHPIMAP;
  13. /**
  14. * Class Address
  15. *
  16. * @package Webklex\PHPIMAP
  17. */
  18. class Address {
  19. /**
  20. * Address attributes
  21. * @var string $personal
  22. * @var string $mailbox
  23. * @var string $host
  24. * @var string $mail
  25. * @var string $full
  26. */
  27. public $personal = "";
  28. public $mailbox = "";
  29. public $host = "";
  30. public $mail = "";
  31. public $full = "";
  32. /**
  33. * Address constructor.
  34. * @param object $object
  35. */
  36. public function __construct($object) {
  37. if (property_exists($object, "personal")){ $this->personal = $object->personal; }
  38. if (property_exists($object, "mailbox")){ $this->mailbox = $object->mailbox; }
  39. if (property_exists($object, "host")){ $this->host = $object->host; }
  40. if (property_exists($object, "mail")){ $this->mail = $object->mail; }
  41. if (property_exists($object, "full")){ $this->full = $object->full; }
  42. }
  43. /**
  44. * Return the stringified address
  45. *
  46. * @return string
  47. */
  48. public function __toString() {
  49. return $this->full ? $this->full : "";
  50. }
  51. /**
  52. * Return the serialized address
  53. *
  54. * @return array
  55. */
  56. public function __serialize(){
  57. return [
  58. "personal" => $this->personal,
  59. "mailbox" => $this->mailbox,
  60. "host" => $this->host,
  61. "mail" => $this->mail,
  62. "full" => $this->full,
  63. ];
  64. }
  65. /**
  66. * Convert instance to array
  67. *
  68. * @return array
  69. */
  70. public function toArray(){
  71. return $this->__serialize();
  72. }
  73. /**
  74. * Return the stringified attribute
  75. *
  76. * @return string
  77. */
  78. public function toString(){
  79. return $this->__toString();
  80. }
  81. }