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