annotate plugins/libcalendaring/lib/Sabre/VObject/Splitter/VCard.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Splitter;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * Splitter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * This class is responsible for splitting up VCard objects.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * It is assumed that the input stream contains 1 or more VCARD objects. This
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * class checks for BEGIN:VCARD and END:VCARD and parses each encountered
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * component individually.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * @author Dominik Tobschall
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * @author Armin Hackmann
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 class VCard implements SplitterInterface {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * File handle
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 * @var resource
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 protected $input;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 * Constructor
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 * The splitter should receive an readable file stream as it's input.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 * @param resource $input
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 public function __construct($input) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 $this->input = $input;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 * Every time getNext() is called, a new object will be parsed, until we
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 * hit the end of the stream.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 * When the end is reached, null will be returned.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 * @return Sabre\VObject\Component|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 public function getNext() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 $vcard = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 do {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 if (feof($this->input)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 $line = fgets($this->input);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 $vcard .= $line;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 } while(strtoupper(substr($line,0,4))!=="END:");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 $object = VObject\Reader::read($vcard);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 if($object->name !== 'VCARD') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 throw new \InvalidArgumentException("Thats no vCard!", 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 return $object;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 }