| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Webklex\PHPIMAP; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
class Address { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public string $personal = ""; |
| 31 |
public string $mailbox = ""; |
| 32 |
public string $host = ""; |
| 33 |
public string $mail = ""; |
| 34 |
public string $full = ""; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public function __construct(object $object) { |
| 41 |
if (property_exists($object, "personal")){ $this->personal = $object->personal ?? ''; } |
| 42 |
if (property_exists($object, "mailbox")){ $this->mailbox = $object->mailbox ?? ''; } |
| 43 |
if (property_exists($object, "host")){ $this->host = $object->host ?? ''; } |
| 44 |
if (property_exists($object, "mail")){ $this->mail = $object->mail ?? ''; } |
| 45 |
if (property_exists($object, "full")){ $this->full = $object->full ?? ''; } |
| 46 |
$this->boot(); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
private function boot(): void { |
| 53 |
if($this->mail === "" && $this->mailbox !== "" && $this->host !== ""){ |
| 54 |
$this->mail = $this->mailbox . "@" . $this->host; |
| 55 |
}elseif($this->mail === "" && $this->mailbox !== ""){ |
| 56 |
$this->mail = $this->mailbox; |
| 57 |
} |
| 58 |
|
| 59 |
if($this->full === "" && $this->mail !== "" && $this->personal !== ""){ |
| 60 |
$this->full = $this->personal . " <" . $this->mail . ">"; |
| 61 |
}elseif($this->full === "" && $this->mail !== ""){ |
| 62 |
$this->full = $this->mail; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function __toString() { |
| 73 |
return $this->full ?: ""; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function __serialize(){ |
| 82 |
return [ |
| 83 |
"personal" => $this->personal, |
| 84 |
"mailbox" => $this->mailbox, |
| 85 |
"host" => $this->host, |
| 86 |
"mail" => $this->mail, |
| 87 |
"full" => $this->full, |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public function toArray(): array { |
| 97 |
return $this->__serialize(); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function toString(): string { |
| 106 |
return $this->__toString(); |
| 107 |
} |
| 108 |
} |