Component
1 year ago
ITip
1 year ago
Parser
1 year ago
Property
1 year ago
Recur
1 year ago
Splitter
1 year ago
TimezoneGuesser
1 year ago
timezonedata
1 year ago
BirthdayCalendarGenerator.php
1 year ago
Cli.php
1 year ago
Component.php
1 year ago
DateTimeParser.php
1 year ago
Document.php
1 year ago
ElementList.php
1 year ago
EofException.php
1 year ago
FreeBusyData.php
1 year ago
FreeBusyGenerator.php
1 year ago
InvalidDataException.php
1 year ago
Node.php
1 year ago
PHPUnitAssertions.php
1 year ago
Parameter.php
1 year ago
ParseException.php
1 year ago
Property.php
1 year ago
Reader.php
1 year ago
Settings.php
1 year ago
StringUtil.php
1 year ago
TimeZoneUtil.php
1 year ago
UUIDUtil.php
1 year ago
VCardConverter.php
1 year ago
Version.php
1 year ago
Writer.php
1 year ago
Writer.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Sabre\VObject; |
| 4 | |
| 5 | use Sabre\Xml; |
| 6 | |
| 7 | /** |
| 8 | * iCalendar/vCard/jCal/jCard/xCal/xCard writer object. |
| 9 | * |
| 10 | * This object provides a few (static) convenience methods to quickly access |
| 11 | * the serializers. |
| 12 | * |
| 13 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 14 | * @author Ivan Enderlin |
| 15 | * @license http://sabre.io/license/ Modified BSD License |
| 16 | */ |
| 17 | class Writer |
| 18 | { |
| 19 | /** |
| 20 | * Serializes a vCard or iCalendar object. |
| 21 | * |
| 22 | * @return string |
| 23 | */ |
| 24 | public static function write(Component $component) |
| 25 | { |
| 26 | return $component->serialize(); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Serializes a jCal or jCard object. |
| 31 | * |
| 32 | * @param int $options |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public static function writeJson(Component $component, $options = 0) |
| 37 | { |
| 38 | return json_encode($component, $options); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Serializes a xCal or xCard object. |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | public static function writeXml(Component $component) |
| 47 | { |
| 48 | $writer = new Xml\Writer(); |
| 49 | $writer->openMemory(); |
| 50 | $writer->setIndent(true); |
| 51 | |
| 52 | $writer->startDocument('1.0', 'utf-8'); |
| 53 | |
| 54 | if ($component instanceof Component\VCalendar) { |
| 55 | $writer->startElement('icalendar'); |
| 56 | $writer->writeAttribute('xmlns', Parser\XML::XCAL_NAMESPACE); |
| 57 | } else { |
| 58 | $writer->startElement('vcards'); |
| 59 | $writer->writeAttribute('xmlns', Parser\XML::XCARD_NAMESPACE); |
| 60 | } |
| 61 | |
| 62 | $component->xmlSerialize($writer); |
| 63 | |
| 64 | $writer->endElement(); |
| 65 | |
| 66 | return $writer->outputMemory(); |
| 67 | } |
| 68 | } |
| 69 |