PushTransports.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2023 Thomas Citharel <nextcloud@tcit.fr>
  5. *
  6. * @author Thomas Citharel <nextcloud@tcit.fr>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\CalDAV\PushSync\Xml;
  24. use OCA\DAV\CalDAV\PushSync\Plugin;
  25. use OCA\DAV\Push\IPushTransport;
  26. use Sabre\Xml\Writer;
  27. use Sabre\Xml\XmlSerializable;
  28. class PushTransports implements XmlSerializable {
  29. /** @var IPushTransport[] */
  30. private array $pushTransports;
  31. public function __construct(array $pushTransports) {
  32. $this->pushTransports = $pushTransports;
  33. }
  34. public function getValue(): array {
  35. return $this->pushTransports;
  36. }
  37. /**
  38. * The xmlSerialize method is called during xml writing.
  39. *
  40. * Use the $writer argument to write its own xml serialization.
  41. *
  42. * An important note: do _not_ create a parent element. Any element
  43. * implementing XmlSerializble should only ever write what's considered
  44. * its 'inner xml'.
  45. *
  46. * The parent of the current element is responsible for writing a
  47. * containing element.
  48. *
  49. * This allows serializers to be re-used for different element names.
  50. *
  51. * If you are opening new elements, you must also close them again.
  52. *
  53. * @param Writer $writer
  54. * @return void
  55. */
  56. public function xmlSerialize(Writer $writer): void {
  57. // $cs = '{' . Plugin::NS_CALENDARSERVER . '}';
  58. if (count($this->pushTransports) <= 0) return;
  59. //$writer->startElement($cs . 'push-transports');
  60. foreach ($this->pushTransports as $pushTransport) {
  61. $pushTransport->xmlSerialize($writer);
  62. // $writer->startElement($cs . 'transport');
  63. // $writer->writeAttribute('type', 'whatever');
  64. //
  65. // $writer->startElement($cs . 'subscription-url');
  66. // $writer->writeElement('{DAV:}href', $pushTransport->getSubscriptionUrl());
  67. // $writer->endElement();
  68. //
  69. // $writer->writeElement('apsbundleid', 'whatever');
  70. // $writer->writeElement('env', 'whatever');
  71. // $writer->writeElement('refresh-interval', $pushTransport->getRefreshInterval());
  72. //
  73. // $writer->endElement(); // transport
  74. }
  75. // $writer->endElement();
  76. }
  77. }