1 | <?php namespace Arcanedev\SeoHelper\Entities\Twitter; |
||
13 | class Card implements CardContract |
||
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\MetaCollection |
||
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 | 328 | public function __construct(array $configs = []) |
|
62 | |||
63 | /** |
||
64 | * Start the engine. |
||
65 | * |
||
66 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
67 | */ |
||
68 | 328 | private function init() |
|
78 | |||
79 | /* ------------------------------------------------------------------------------------------------ |
||
80 | | Getters & Setters |
||
81 | | ------------------------------------------------------------------------------------------------ |
||
82 | */ |
||
83 | /** |
||
84 | * Set meta prefix name. |
||
85 | * |
||
86 | * @param string $prefix |
||
87 | * |
||
88 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
89 | */ |
||
90 | 328 | private function setPrefix($prefix) |
|
96 | |||
97 | /** |
||
98 | * Set the card type. |
||
99 | * |
||
100 | * @param string $type |
||
101 | * |
||
102 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
103 | */ |
||
104 | 328 | public function setType($type) |
|
113 | |||
114 | /** |
||
115 | * Set card site. |
||
116 | * |
||
117 | * @param string $site |
||
118 | * |
||
119 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
120 | */ |
||
121 | 328 | public function setSite($site) |
|
129 | |||
130 | /** |
||
131 | * Set card title. |
||
132 | * |
||
133 | * @param string $title |
||
134 | * |
||
135 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
136 | */ |
||
137 | 328 | public function setTitle($title) |
|
141 | |||
142 | /** |
||
143 | * Set card description. |
||
144 | * |
||
145 | * @param string $description |
||
146 | * |
||
147 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
148 | */ |
||
149 | 40 | public function setDescription($description) |
|
153 | |||
154 | /** |
||
155 | * Add image to the card. |
||
156 | * |
||
157 | * @param string $url |
||
158 | * |
||
159 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
160 | */ |
||
161 | 40 | public function addImage($url) |
|
169 | |||
170 | /** |
||
171 | * Add many metas to the card. |
||
172 | * |
||
173 | * @param array $metas |
||
174 | * |
||
175 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
176 | */ |
||
177 | 328 | public function addMetas(array $metas) |
|
183 | |||
184 | /** |
||
185 | * Add a meta to the card. |
||
186 | * |
||
187 | * @param string $name |
||
188 | * @param string $content |
||
189 | * |
||
190 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
191 | */ |
||
192 | 328 | public function addMeta($name, $content) |
|
198 | |||
199 | /** |
||
200 | * Get all supported card types. |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | 328 | public function types() |
|
216 | |||
217 | /* ------------------------------------------------------------------------------------------------ |
||
218 | | Main Functions |
||
219 | | ------------------------------------------------------------------------------------------------ |
||
220 | */ |
||
221 | /** |
||
222 | * Render card images. |
||
223 | */ |
||
224 | 40 | private function loadImages() |
|
236 | |||
237 | /** |
||
238 | * Reset the card. |
||
239 | * |
||
240 | * @return \Arcanedev\SeoHelper\Entities\Twitter\Card |
||
241 | */ |
||
242 | 16 | public function reset() |
|
249 | |||
250 | /** |
||
251 | * Render the twitter card. |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | 232 | public function render() |
|
263 | |||
264 | /** |
||
265 | * Render the tag. |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 64 | public function __toString() |
|
273 | |||
274 | /* ------------------------------------------------------------------------------------------------ |
||
275 | | Check Functions |
||
276 | | ------------------------------------------------------------------------------------------------ |
||
277 | */ |
||
278 | /** |
||
279 | * Check the card type. |
||
280 | * |
||
281 | * @param string $type |
||
282 | * |
||
283 | * @throws \Arcanedev\SeoHelper\Exceptions\InvalidTwitterCardException |
||
284 | */ |
||
285 | 328 | private function checkType(&$type) |
|
299 | |||
300 | /** |
||
301 | * Check the card site. |
||
302 | * |
||
303 | * @param string $site |
||
304 | */ |
||
305 | 328 | private function checkSite(&$site) |
|
309 | |||
310 | /* ------------------------------------------------------------------------------------------------ |
||
311 | | Other Functions |
||
312 | | ------------------------------------------------------------------------------------------------ |
||
313 | */ |
||
314 | /** |
||
315 | * Prepare username. |
||
316 | * |
||
317 | * @param string $username |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | 328 | private function prepareUsername($username) |
|
329 | } |
||
330 |