SearchBinaryOperator.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Files\Search;
  7. use OCP\Files\Search\ISearchBinaryOperator;
  8. use OCP\Files\Search\ISearchOperator;
  9. class SearchBinaryOperator implements ISearchBinaryOperator {
  10. /** @var string */
  11. private $type;
  12. /** @var (SearchBinaryOperator|SearchComparison)[] */
  13. private $arguments;
  14. private $hints = [];
  15. /**
  16. * SearchBinaryOperator constructor.
  17. *
  18. * @param string $type
  19. * @param (SearchBinaryOperator|SearchComparison)[] $arguments
  20. */
  21. public function __construct($type, array $arguments) {
  22. $this->type = $type;
  23. $this->arguments = $arguments;
  24. }
  25. /**
  26. * @return string
  27. */
  28. public function getType() {
  29. return $this->type;
  30. }
  31. /**
  32. * @return ISearchOperator[]
  33. */
  34. public function getArguments() {
  35. return $this->arguments;
  36. }
  37. /**
  38. * @param ISearchOperator[] $arguments
  39. * @return void
  40. */
  41. public function setArguments(array $arguments): void {
  42. $this->arguments = $arguments;
  43. }
  44. public function getQueryHint(string $name, $default) {
  45. return $this->hints[$name] ?? $default;
  46. }
  47. public function setQueryHint(string $name, $value): void {
  48. $this->hints[$name] = $value;
  49. }
  50. public function __toString(): string {
  51. if ($this->type === ISearchBinaryOperator::OPERATOR_NOT) {
  52. return '(not ' . $this->arguments[0] . ')';
  53. }
  54. return '(' . implode(' ' . $this->type . ' ', $this->arguments) . ')';
  55. }
  56. }