Provider.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\Search;
  8. /**
  9. * Provides a template for search functionality throughout Nextcloud;
  10. * @since 7.0.0
  11. * @deprecated 20.0.0
  12. */
  13. abstract class Provider {
  14. /**
  15. * @since 8.0.0
  16. * @deprecated 20.0.0
  17. */
  18. public const OPTION_APPS = 'apps';
  19. /**
  20. * List of options
  21. * @var array
  22. * @since 7.0.0
  23. * @deprecated 20.0.0
  24. */
  25. protected $options;
  26. /**
  27. * Constructor
  28. * @param array $options as key => value
  29. * @since 7.0.0 - default value for $options was added in 8.0.0
  30. * @deprecated 20.0.0
  31. */
  32. public function __construct($options = []) {
  33. $this->options = $options;
  34. }
  35. /**
  36. * get a value from the options array or null
  37. * @param string $key
  38. * @return mixed
  39. * @since 8.0.0
  40. * @deprecated 20.0.0
  41. */
  42. public function getOption($key) {
  43. if (is_array($this->options) && isset($this->options[$key])) {
  44. return $this->options[$key];
  45. } else {
  46. return null;
  47. }
  48. }
  49. /**
  50. * checks if the given apps and the apps this provider has results for intersect
  51. * returns true if the given array is empty (all apps)
  52. * or if this provider does not have a list of apps it provides results for (legacy search providers)
  53. * or if the two above arrays have elements in common (intersect)
  54. * @param string[] $apps
  55. * @return bool
  56. * @since 8.0.0
  57. * @deprecated 20.0.0
  58. */
  59. public function providesResultsFor(array $apps = []) {
  60. $forApps = $this->getOption(self::OPTION_APPS);
  61. return empty($apps) || empty($forApps) || array_intersect($forApps, $apps);
  62. }
  63. /**
  64. * Search for $query
  65. * @param string $query
  66. * @return array An array of OCP\Search\Result's
  67. * @since 7.0.0
  68. * @deprecated 20.0.0
  69. */
  70. abstract public function search($query);
  71. }