1 | <?php |
||
23 | class VCardBuilder |
||
24 | { |
||
25 | /** |
||
26 | * FileName |
||
27 | * |
||
28 | * @var string|null |
||
29 | */ |
||
30 | private $fileName; |
||
31 | |||
32 | /** |
||
33 | * Properties |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $properties; |
||
38 | |||
39 | /** |
||
40 | * Default Charset |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $charset; |
||
45 | |||
46 | /** |
||
47 | * VCardBuilder constructor. |
||
48 | * |
||
49 | * @param VCard|VCard[] $vCard |
||
50 | * @param string $charset |
||
51 | * |
||
52 | * @throws ElementAlreadyExistsException |
||
53 | */ |
||
54 | public function __construct($vCard, $charset = 'utf-8') |
||
63 | |||
64 | /** |
||
65 | * Build VCard (.vcf) |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | public function buildVCard(): string |
||
89 | |||
90 | /** |
||
91 | * Build VCalender (.ics) - Safari (< iOS 8) can not open .vcf files, so we have build a workaround. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function buildVCalendar(): string |
||
131 | |||
132 | /** |
||
133 | * Download a vcard or vcal file to the browser. |
||
134 | */ |
||
135 | public function download(): void |
||
147 | |||
148 | /** |
||
149 | * Get charset |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getCharset(): string |
||
157 | |||
158 | /** |
||
159 | * Get charset string |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getCharsetString(): string |
||
173 | |||
174 | /** |
||
175 | * Set filename |
||
176 | * |
||
177 | * @param string|array $value |
||
178 | * @param bool $overwrite [optional] Default overwrite is true |
||
179 | * @param string $separator [optional] Default separator is an underscore '_' |
||
180 | * @return void |
||
181 | */ |
||
182 | public function setFileName($value, $overwrite = true, $separator = '_'): void |
||
215 | |||
216 | /** |
||
217 | * Get filename |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | public function getFileName(): string |
||
229 | |||
230 | /** |
||
231 | * Get content type |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getContentType(): string |
||
240 | |||
241 | /** |
||
242 | * Get file extension |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | public function getFileExtension(): string |
||
251 | |||
252 | /** |
||
253 | * Get full filename |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | public function getFullFileName(): string |
||
261 | |||
262 | /** |
||
263 | * Get headers |
||
264 | * |
||
265 | * @param bool $asAssociative |
||
266 | * @return array |
||
267 | */ |
||
268 | public function getHeaders(bool $asAssociative): array |
||
291 | |||
292 | /** |
||
293 | * Get output as string |
||
294 | * iOS devices (and safari < iOS 8 in particular) can not read .vcf (= vcard) files. |
||
295 | * So I build a workaround to build a .ics (= vcalender) file. |
||
296 | * |
||
297 | * @return string |
||
298 | */ |
||
299 | public function getOutput(): string |
||
306 | |||
307 | /** |
||
308 | * Get properties |
||
309 | * |
||
310 | * @return array |
||
311 | */ |
||
312 | public function getProperties(): array |
||
316 | |||
317 | /** |
||
318 | * Has property |
||
319 | * |
||
320 | * @param string $key |
||
321 | * @return bool |
||
322 | */ |
||
323 | public function hasProperty(string $key): bool |
||
335 | |||
336 | /** |
||
337 | * Save to a file |
||
338 | * |
||
339 | * @param string|null $savePath |
||
340 | * |
||
341 | * @return void |
||
342 | * @throws OutputDirectoryNotExistsException |
||
343 | */ |
||
344 | public function save(string $savePath = null): void |
||
360 | |||
361 | /** |
||
362 | * Check the save path directory |
||
363 | * |
||
364 | * @param string $savePath Save Path |
||
365 | * |
||
366 | * @return string |
||
367 | * @throws OutputDirectoryNotExistsException |
||
368 | */ |
||
369 | private static function checkSavePath($savePath): string |
||
382 | } |
||
383 |