Debian Codegraph @

lib/3rdParty/composer/webklex/php-imap/src/Address.php

raw symbols SCIP
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
13 namespace Webklex\PHPIMAP;
14
15 /**
16 * Class Address
17 *
18 * @package Webklex\PHPIMAP
19 */
20 class Address {
21
22 /**
23 * Address attributes
24 * @var string $personal
25 * @var string $mailbox
26 * @var string $host
27 * @var string $mail
28 * @var string $full
29 */
30 public string $personal = "";
31 public string $mailbox = "";
32 public string $host = "";
33 public string $mail = "";
34 public string $full = "";
35
36 /**
37 * Address constructor.
38 * @param object $object
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 * Boot the address
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 * Return the stringified address
69 *
70 * @return string
71 */
72 public function __toString() {
73 return $this->full ?: "";
74 }
75
76 /**
77 * Return the serialized address
78 *
79 * @return array
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 * Convert instance to array
93 *
94 * @return array
95 */
96 public function toArray(): array {
97 return $this->__serialize();
98 }
99
100 /**
101 * Return the stringified attribute
102 *
103 * @return string
104 */
105 public function toString(): string {
106 return $this->__toString();
107 }
108 }