comparison vendor/sabre/vobject/lib/Splitter/VCard.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
comparison
equal deleted inserted replaced
6:cec75ba50afc 7:430dbd5346f7
1 <?php
2
3 namespace Sabre\VObject\Splitter;
4
5 use
6 Sabre\VObject,
7 Sabre\VObject\Parser\MimeDir;
8
9 /**
10 * Splitter
11 *
12 * This class is responsible for splitting up VCard objects.
13 *
14 * It is assumed that the input stream contains 1 or more VCARD objects. This
15 * class checks for BEGIN:VCARD and END:VCARD and parses each encountered
16 * component individually.
17 *
18 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
19 * @author Dominik Tobschall
20 * @author Armin Hackmann
21 * @license http://sabre.io/license/ Modified BSD License
22 */
23 class VCard implements SplitterInterface {
24
25 /**
26 * File handle
27 *
28 * @var resource
29 */
30 protected $input;
31
32 /**
33 * Persistent parser
34 *
35 * @var MimeDir
36 */
37 protected $parser;
38
39 /**
40 * Constructor
41 *
42 * The splitter should receive an readable file stream as it's input.
43 *
44 * @param resource $input
45 * @param int $options Parser options, see the OPTIONS constants.
46 */
47 public function __construct($input, $options = 0) {
48
49 $this->input = $input;
50 $this->parser = new MimeDir($input, $options);
51
52 }
53
54 /**
55 * Every time getNext() is called, a new object will be parsed, until we
56 * hit the end of the stream.
57 *
58 * When the end is reached, null will be returned.
59 *
60 * @return Sabre\VObject\Component|null
61 */
62 public function getNext() {
63
64 try {
65 $object = $this->parser->parse();
66
67 if (!$object instanceof VObject\Component\VCard) {
68 throw new VObject\ParseException('The supplied input contained non-VCARD data.');
69 }
70
71 } catch (VObject\EofException $e) {
72 return null;
73 }
74
75 return $object;
76
77 }
78
79 }