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