1 | <?php |
||
16 | class PersonName |
||
17 | { |
||
18 | const POSSESSIVE_FIRST = 'first'; |
||
19 | const POSSESSIVE_LAST = 'last'; |
||
20 | const POSSESSIVE_FULL = 'full'; |
||
21 | const POSSESSIVE_INITIALS = 'initials'; |
||
22 | const POSSESSIVE_SORTED = 'sorted'; |
||
23 | const POSSESSIVE_ABBREVIATED = 'abbreviated'; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $first; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $last; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | public $wordSplitters = []; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | public $lowercaseExceptions = []; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | public $uppercaseExceptions = []; |
||
49 | |||
50 | 11 | public static function make(?string $fullName = null): ?self |
|
56 | |||
57 | /** |
||
58 | * Creates a new PersonName instance. |
||
59 | * |
||
60 | * @param string $first |
||
61 | * @param string $last |
||
62 | */ |
||
63 | 29 | public function __construct(string $first, ?string $last = null) |
|
71 | |||
72 | 8 | public function first(): string |
|
76 | |||
77 | 8 | public function last(): ?string |
|
81 | |||
82 | /** |
||
83 | * Returns first + last, such as "Jason Fried". |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 19 | public function full(): string |
|
91 | |||
92 | /** |
||
93 | * Returns first + last initial, such as "Jason F.". |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 7 | public function familiar(): string |
|
101 | |||
102 | /** |
||
103 | * Returns first initial + last, such as "J. Fried". |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | 3 | public function abbreviated(): string |
|
111 | |||
112 | /** |
||
113 | * Returns last + first for sorting. |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 3 | public function sorted(): string |
|
121 | |||
122 | /** |
||
123 | * Returns full name with with trailing 's or ' if name ends in s. |
||
124 | * |
||
125 | * @param string $method |
||
126 | * @return string |
||
127 | */ |
||
128 | 7 | public function possessive(string $method = self::POSSESSIVE_FULL): string |
|
132 | |||
133 | /** |
||
134 | * Returns just the initials. |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | 7 | public function initials(): string |
|
144 | |||
145 | /** |
||
146 | * Returns a mentionable version of the familiar name. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 3 | public function mentionable(): string |
|
154 | |||
155 | /** |
||
156 | * Returns a proper name case version of the full name. |
||
157 | * @param string $name Which part of the name to proper case. Default full|first|last. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 3 | public function proper($name = null): string |
|
194 | |||
195 | /** |
||
196 | * Make the methods accessibles as attributes. |
||
197 | * |
||
198 | * @param string $attribute |
||
199 | * @return mixed |
||
200 | */ |
||
201 | 27 | public function __get($attribute) |
|
205 | |||
206 | 14 | public function __toString(): string |
|
210 | } |
||
211 |