PageRenderTime 77ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Sabre/DAV/Property/SupportedReportSet.php

https://github.com/KOLANICH/SabreDAV
PHP | 126 lines | 43 code | 31 blank | 52 comment | 5 complexity | e25b529f6c6c05dfdc928c6c29bd2d33 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\DAV\Property;
  3. use Sabre\DAV;
  4. /**
  5. * supported-report-set property.
  6. *
  7. * This property is defined in RFC3253, but since it's
  8. * so common in other webdav-related specs, it is part of the core server.
  9. *
  10. * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class SupportedReportSet extends DAV\Property {
  15. /**
  16. * List of reports
  17. *
  18. * @var array
  19. */
  20. protected $reports = array();
  21. /**
  22. * Creates the property
  23. *
  24. * Any reports passed in the constructor
  25. * should be valid report-types in clark-notation.
  26. *
  27. * Either a string or an array of strings must be passed.
  28. *
  29. * @param mixed $reports
  30. */
  31. public function __construct($reports = null) {
  32. if (!is_null($reports))
  33. $this->addReport($reports);
  34. }
  35. /**
  36. * Adds a report to this property
  37. *
  38. * The report must be a string in clark-notation.
  39. * Multiple reports can be specified as an array.
  40. *
  41. * @param mixed $report
  42. * @return void
  43. */
  44. public function addReport($report) {
  45. if (!is_array($report)) $report = array($report);
  46. foreach($report as $r) {
  47. if (!preg_match('/^{([^}]*)}(.*)$/',$r))
  48. throw new DAV\Exception('Reportname must be in clark-notation');
  49. $this->reports[] = $r;
  50. }
  51. }
  52. /**
  53. * Returns the list of supported reports
  54. *
  55. * @return array
  56. */
  57. public function getValue() {
  58. return $this->reports;
  59. }
  60. /**
  61. * Returns true or false if the property contains a specific report.
  62. *
  63. * @param string $reportName
  64. * @return bool
  65. */
  66. public function has($reportName) {
  67. return in_array(
  68. $reportName,
  69. $this->reports
  70. );
  71. }
  72. /**
  73. * Serializes the node
  74. *
  75. * @param DAV\Server $server
  76. * @param \DOMElement $prop
  77. * @return void
  78. */
  79. public function serialize(DAV\Server $server, \DOMElement $prop) {
  80. foreach($this->reports as $reportName) {
  81. $supportedReport = $prop->ownerDocument->createElement('d:supported-report');
  82. $prop->appendChild($supportedReport);
  83. $report = $prop->ownerDocument->createElement('d:report');
  84. $supportedReport->appendChild($report);
  85. preg_match('/^{([^}]*)}(.*)$/',$reportName,$matches);
  86. list(, $namespace, $element) = $matches;
  87. $prefix = isset($server->xmlNamespaces[$namespace])?$server->xmlNamespaces[$namespace]:null;
  88. if ($prefix) {
  89. $report->appendChild($prop->ownerDocument->createElement($prefix . ':' . $element));
  90. } else {
  91. $report->appendChild($prop->ownerDocument->createElementNS($namespace, 'x:' . $element));
  92. }
  93. }
  94. }
  95. }