1 | <?php namespace Arcanedev\SeoHelper\Entities\Twitter; |
||
13 | class Card implements TwitterCardInterface |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Traits |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | use Configurable; |
||
20 | |||
21 | /* ------------------------------------------------------------------------------------------------ |
||
22 | | Properties |
||
23 | | ------------------------------------------------------------------------------------------------ |
||
24 | */ |
||
25 | /** |
||
26 | * Card type. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $type; |
||
31 | |||
32 | /** |
||
33 | * Card meta collection. |
||
34 | * |
||
35 | * @var \Arcanedev\SeoHelper\Contracts\Entities\MetaCollectionInterface |
||
36 | */ |
||
37 | protected $metas; |
||
38 | |||
39 | /** |
||
40 | * Card images. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $images = []; |
||
45 | |||
46 | /* ------------------------------------------------------------------------------------------------ |
||
47 | | Constructor |
||
48 | | ------------------------------------------------------------------------------------------------ |
||
49 | */ |
||
50 | /** |
||
51 | * Make the twitter card instance. |
||
52 | * |
||
53 | * @param array $configs |
||
54 | */ |
||
55 | 480 | public function __construct(array $configs = []) |
|
62 | |||
63 | /** |
||
64 | * Start the engine. |
||
65 | * |
||
66 | * @return self |
||
67 | */ |
||
68 | 480 | private function init() |
|
78 | |||
79 | /* ------------------------------------------------------------------------------------------------ |
||
80 | | Getters & Setters |
||
81 | | ------------------------------------------------------------------------------------------------ |
||
82 | */ |
||
83 | /** |
||
84 | * Set meta prefix name. |
||
85 | * |
||
86 | * @param string $prefix |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | 480 | private function setPrefix($prefix) |
|
96 | |||
97 | /** |
||
98 | * Set the card type. |
||
99 | * |
||
100 | * @param string $type |
||
101 | * |
||
102 | * @return self |
||
103 | */ |
||
104 | 480 | public function setType($type) |
|
115 | |||
116 | /** |
||
117 | * Set card site. |
||
118 | * |
||
119 | * @param string $site |
||
120 | * |
||
121 | * @return self |
||
122 | */ |
||
123 | 480 | public function setSite($site) |
|
132 | |||
133 | /** |
||
134 | * Set card title. |
||
135 | * |
||
136 | * @param string $title |
||
137 | * |
||
138 | * @return self |
||
139 | */ |
||
140 | 480 | public function setTitle($title) |
|
146 | |||
147 | /** |
||
148 | * Set card description. |
||
149 | * |
||
150 | * @param string $description |
||
151 | * |
||
152 | * @return self |
||
153 | */ |
||
154 | 60 | public function setDescription($description) |
|
160 | |||
161 | /** |
||
162 | * Add image to the card. |
||
163 | * |
||
164 | * @param string $url |
||
165 | * |
||
166 | * @return self |
||
167 | */ |
||
168 | 60 | public function addImage($url) |
|
176 | |||
177 | /** |
||
178 | * Add many metas to the card. |
||
179 | * |
||
180 | * @param array $metas |
||
181 | * |
||
182 | * @return self |
||
183 | */ |
||
184 | 480 | public function addMetas(array $metas) |
|
192 | |||
193 | /** |
||
194 | * Add a meta to the card. |
||
195 | * |
||
196 | * @param string $name |
||
197 | * @param string $content |
||
198 | * |
||
199 | * @return self |
||
200 | */ |
||
201 | 480 | public function addMeta($name, $content) |
|
207 | |||
208 | /** |
||
209 | * Get all supported card types. |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 480 | public function types() |
|
225 | |||
226 | /* ------------------------------------------------------------------------------------------------ |
||
227 | | Main Functions |
||
228 | | ------------------------------------------------------------------------------------------------ |
||
229 | */ |
||
230 | /** |
||
231 | * Render card images. |
||
232 | */ |
||
233 | 60 | private function loadImages() |
|
245 | |||
246 | /** |
||
247 | * Reset the card. |
||
248 | * |
||
249 | * @return self |
||
250 | */ |
||
251 | 24 | public function reset() |
|
258 | |||
259 | /** |
||
260 | * Render the twitter card. |
||
261 | * |
||
262 | * @return string |
||
263 | */ |
||
264 | 336 | public function render() |
|
272 | |||
273 | /** |
||
274 | * Render the tag. |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | 96 | public function __toString() |
|
282 | |||
283 | /* ------------------------------------------------------------------------------------------------ |
||
284 | | Check Functions |
||
285 | | ------------------------------------------------------------------------------------------------ |
||
286 | */ |
||
287 | /** |
||
288 | * Check the card type. |
||
289 | * |
||
290 | * @param string $type |
||
291 | * |
||
292 | * @throws \Arcanedev\SeoHelper\Exceptions\InvalidTwitterCardException |
||
293 | */ |
||
294 | 480 | private function checkType(&$type) |
|
310 | |||
311 | /** |
||
312 | * Check the card site. |
||
313 | * |
||
314 | * @param string $site |
||
315 | */ |
||
316 | 480 | private function checkSite(&$site) |
|
320 | |||
321 | /* ------------------------------------------------------------------------------------------------ |
||
322 | | Other Functions |
||
323 | | ------------------------------------------------------------------------------------------------ |
||
324 | */ |
||
325 | /** |
||
326 | * Prepare username. |
||
327 | * |
||
328 | * @param string $username |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | 480 | private function prepareUsername($username) |
|
340 | } |
||
341 |