Card.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\ContactsInteraction;
  8. use OCA\ContactsInteraction\Db\RecentContact;
  9. use Sabre\CardDAV\ICard;
  10. use Sabre\DAV\Exception\NotImplemented;
  11. use Sabre\DAVACL\ACLTrait;
  12. use Sabre\DAVACL\IACL;
  13. class Card implements ICard, IACL {
  14. use ACLTrait;
  15. public function __construct(
  16. private RecentContact $contact,
  17. private string $principal,
  18. private array $acls,
  19. ) {
  20. }
  21. /**
  22. * @inheritDoc
  23. */
  24. public function getOwner(): ?string {
  25. return $this->principal;
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. public function getACL(): array {
  31. return $this->acls;
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. public function setAcls(array $acls): void {
  37. throw new NotImplemented();
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. public function put($data): ?string {
  43. throw new NotImplemented();
  44. }
  45. /**
  46. * @inheritDoc
  47. */
  48. public function get(): string {
  49. return $this->contact->getCard();
  50. }
  51. /**
  52. * @inheritDoc
  53. */
  54. public function getContentType(): ?string {
  55. return 'text/vcard; charset=utf-8';
  56. }
  57. /**
  58. * @inheritDoc
  59. */
  60. public function getETag(): ?string {
  61. return '"' . md5((string) $this->getLastModified()) . '"';
  62. }
  63. /**
  64. * @inheritDoc
  65. */
  66. public function getSize(): int {
  67. return strlen($this->contact->getCard());
  68. }
  69. /**
  70. * @inheritDoc
  71. */
  72. public function delete(): void {
  73. throw new NotImplemented();
  74. }
  75. /**
  76. * @inheritDoc
  77. */
  78. public function getName(): string {
  79. return (string) $this->contact->getId();
  80. }
  81. /**
  82. * @inheritDoc
  83. */
  84. public function setName($name): void {
  85. throw new NotImplemented();
  86. }
  87. /**
  88. * @inheritDoc
  89. */
  90. public function getLastModified(): ?int {
  91. return $this->contact->getLastContact();
  92. }
  93. }