SupportedAddressData.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Supported-address-data property
  4. *
  5. * This property is a representation of the supported-address-data property
  6. * in the CardDAV namespace.
  7. *
  8. * @package Sabre
  9. * @subpackage CardDAV
  10. * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
  11. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class Sabre_CardDAV_Property_SupportedAddressData extends Sabre_DAV_Property {
  15. /**
  16. * supported versions
  17. *
  18. * @var array
  19. */
  20. protected $supportedData = array();
  21. /**
  22. * Creates the property
  23. *
  24. * @param array $components
  25. */
  26. public function __construct(array $supportedData = null) {
  27. if (is_null($supportedData)) {
  28. $supportedData = array(
  29. array('contentType' => 'text/vcard', 'version' => '3.0'),
  30. array('contentType' => 'text/vcard', 'version' => '4.0'),
  31. );
  32. }
  33. $this->supportedData = $supportedData;
  34. }
  35. /**
  36. * Serializes the property in a DOMDocument
  37. *
  38. * @param Sabre_DAV_Server $server
  39. * @param DOMElement $node
  40. * @return void
  41. */
  42. public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
  43. $doc = $node->ownerDocument;
  44. $prefix =
  45. isset($server->xmlNamespaces[Sabre_CardDAV_Plugin::NS_CARDDAV]) ?
  46. $server->xmlNamespaces[Sabre_CardDAV_Plugin::NS_CARDDAV] :
  47. 'card';
  48. foreach($this->supportedData as $supported) {
  49. $caldata = $doc->createElementNS(Sabre_CardDAV_Plugin::NS_CARDDAV, $prefix . ':address-data-type');
  50. $caldata->setAttribute('content-type',$supported['contentType']);
  51. $caldata->setAttribute('version',$supported['version']);
  52. $node->appendChild($caldata);
  53. }
  54. }
  55. }