1 | <?php |
||
6 | trait UserPresenter |
||
7 | { |
||
8 | /** |
||
9 | * The default avatar used when there is no avatar for the user. |
||
10 | * |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $defaultAvatar = '/images/avatar.png'; |
||
14 | |||
15 | /** |
||
16 | * Get the account first name. |
||
17 | * |
||
18 | * @return string |
||
19 | */ |
||
20 | public function getFirstNameAttribute(): string |
||
24 | |||
25 | /** |
||
26 | * Get the account last name. |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | public function getLastNameAttribute(): string |
||
34 | |||
35 | /** |
||
36 | * Get the account full name. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getFullNameAttribute(): string |
||
44 | |||
45 | /** |
||
46 | * Get the account facebook. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getFacebookAttribute(): string |
||
54 | |||
55 | /** |
||
56 | * Get the account twitter. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getTwitterAttribute(): string |
||
64 | |||
65 | /** |
||
66 | * Get the account biography. |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getBiographyAttribute(): string |
||
74 | |||
75 | /** |
||
76 | * Get the account signature. |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getSignatureAttribute(): string |
||
84 | |||
85 | /** |
||
86 | * Get the small avatar. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getAvatarSmallAttribute(): string |
||
94 | |||
95 | /** |
||
96 | * Get the medium avatar. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getAvatarMediumAttribute(): string |
||
104 | |||
105 | /** |
||
106 | * Get the big avatar. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getAvatarBigAttribute(): string |
||
114 | |||
115 | /** |
||
116 | * Get the profile background. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getProfileBackgroundAttribute(): string |
||
124 | |||
125 | /** |
||
126 | * Get the profile url. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getProfileUrlAttribute(): string |
||
138 | |||
139 | /** |
||
140 | * Parse a mdedia and return it if isset or return the default avatar. |
||
141 | * |
||
142 | * @param string $type The type of the media to get. |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function parseMedia(string $type): string |
||
154 | |||
155 | /** |
||
156 | * Parse an attribute and return its value or empty if null. |
||
157 | * |
||
158 | * @param Object|null $relation The relation or the user object. |
||
159 | * Can be `$this` or `$this->account` for exemple |
||
160 | * @param string|null $attribute The attribute to parse. |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function parse($relation, $attribute): string |
||
172 | } |
||
173 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: