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