AbstractBackend.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAVACL\PrincipalBackend;
  4. /**
  5. * Abstract Principal Backend.
  6. *
  7. * Currently this class has no function. It's here for consistency and so we
  8. * have a non-bc-breaking way to add a default generic implementation to
  9. * functions we may add in the future.
  10. *
  11. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  12. * @author Evert Pot (http://evertpot.com/)
  13. * @license http://sabre.io/license/ Modified BSD License
  14. */
  15. abstract class AbstractBackend implements BackendInterface
  16. {
  17. /**
  18. * Finds a principal by its URI.
  19. *
  20. * This method may receive any type of uri, but mailto: addresses will be
  21. * the most common.
  22. *
  23. * Implementation of this API is optional. It is currently used by the
  24. * CalDAV system to find principals based on their email addresses. If this
  25. * API is not implemented, some features may not work correctly.
  26. *
  27. * This method must return a relative principal path, or null, if the
  28. * principal was not found or you refuse to find it.
  29. *
  30. * @param string $uri
  31. * @param string $principalPrefix
  32. *
  33. * @return string|null
  34. */
  35. public function findByUri($uri, $principalPrefix)
  36. {
  37. // Note that the default implementation here is a bit slow and could
  38. // likely be optimized.
  39. if ('mailto:' !== substr($uri, 0, 7)) {
  40. return;
  41. }
  42. $result = $this->searchPrincipals(
  43. $principalPrefix,
  44. ['{http://sabredav.org/ns}email-address' => substr($uri, 7)]
  45. );
  46. if ($result) {
  47. return $result[0];
  48. }
  49. }
  50. }