1
0

Provider.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Andrew Brown <andrew@casabrown.com>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Jakob Sack <mail@jakobsack.de>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCP\Search;
  28. /**
  29. * Provides a template for search functionality throughout Nextcloud;
  30. * @since 7.0.0
  31. * @deprecated 20.0.0
  32. */
  33. abstract class Provider {
  34. /**
  35. * @since 8.0.0
  36. * @deprecated 20.0.0
  37. */
  38. public const OPTION_APPS = 'apps';
  39. /**
  40. * List of options
  41. * @var array
  42. * @since 7.0.0
  43. * @deprecated 20.0.0
  44. */
  45. protected $options;
  46. /**
  47. * Constructor
  48. * @param array $options as key => value
  49. * @since 7.0.0 - default value for $options was added in 8.0.0
  50. * @deprecated 20.0.0
  51. */
  52. public function __construct($options = []) {
  53. $this->options = $options;
  54. }
  55. /**
  56. * get a value from the options array or null
  57. * @param string $key
  58. * @return mixed
  59. * @since 8.0.0
  60. * @deprecated 20.0.0
  61. */
  62. public function getOption($key) {
  63. if (is_array($this->options) && isset($this->options[$key])) {
  64. return $this->options[$key];
  65. } else {
  66. return null;
  67. }
  68. }
  69. /**
  70. * checks if the given apps and the apps this provider has results for intersect
  71. * returns true if the given array is empty (all apps)
  72. * or if this provider does not have a list of apps it provides results for (legacy search providers)
  73. * or if the two above arrays have elements in common (intersect)
  74. * @param string[] $apps
  75. * @return bool
  76. * @since 8.0.0
  77. * @deprecated 20.0.0
  78. */
  79. public function providesResultsFor(array $apps = []) {
  80. $forApps = $this->getOption(self::OPTION_APPS);
  81. return empty($apps) || empty($forApps) || array_intersect($forApps, $apps);
  82. }
  83. /**
  84. * Search for $query
  85. * @param string $query
  86. * @return array An array of OCP\Search\Result's
  87. * @since 7.0.0
  88. * @deprecated 20.0.0
  89. */
  90. abstract public function search($query);
  91. }