PageRenderTime 142ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 57ms app.codeStats 0ms

/lib/Sabre/CardDAV/Property/SupportedAddressData.php

https://github.com/KOLANICH/SabreDAV
PHP | 72 lines | 28 code | 16 blank | 28 comment | 1 complexity | 2dd749a7f51082261c16bdc33bfebf2a MD5 | raw file
 1<?php
 2
 3namespace Sabre\CardDAV\Property;
 4
 5use Sabre\DAV;
 6use Sabre\CardDAV;
 7
 8/**
 9 * Supported-address-data property
10 *
11 * This property is a representation of the supported-address-data property
12 * in the CardDAV namespace.
13 *
14 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
15 * @author Evert Pot (http://evertpot.com/)
16 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
17 */
18class SupportedAddressData extends DAV\Property {
19
20    /**
21     * supported versions
22     *
23     * @var array
24     */
25    protected $supportedData = array();
26
27    /**
28     * Creates the property
29     *
30     * @param array|null $supportedData
31     */
32    public function __construct(array $supportedData = null) {
33
34        if (is_null($supportedData)) {
35            $supportedData = array(
36                array('contentType' => 'text/vcard', 'version' => '3.0'),
37                // array('contentType' => 'text/vcard', 'version' => '4.0'),
38            );
39        }
40
41       $this->supportedData = $supportedData;
42
43    }
44
45    /**
46     * Serializes the property in a DOMDocument
47     *
48     * @param DAV\Server $server
49     * @param \DOMElement $node
50     * @return void
51     */
52    public function serialize(DAV\Server $server,\DOMElement $node) {
53
54        $doc = $node->ownerDocument;
55
56        $prefix =
57            isset($server->xmlNamespaces[CardDAV\Plugin::NS_CARDDAV]) ?
58            $server->xmlNamespaces[CardDAV\Plugin::NS_CARDDAV] :
59            'card';
60
61        foreach($this->supportedData as $supported) {
62
63            $caldata = $doc->createElementNS(CardDAV\Plugin::NS_CARDDAV, $prefix . ':address-data-type');
64            $caldata->setAttribute('content-type',$supported['contentType']);
65            $caldata->setAttribute('version',$supported['version']);
66            $node->appendChild($caldata);
67
68        }
69
70    }
71
72}