SearchComparison.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Files\Search;
  8. use OCP\Files\Search\ISearchComparison;
  9. /**
  10. * @psalm-import-type ParamValue from ISearchComparison
  11. */
  12. class SearchComparison implements ISearchComparison {
  13. private array $hints = [];
  14. public function __construct(
  15. private string $type,
  16. private string $field,
  17. /** @var ParamValue $value */
  18. private \DateTime|int|string|bool|array $value,
  19. private string $extra = ''
  20. ) {
  21. }
  22. /**
  23. * @return string
  24. */
  25. public function getType(): string {
  26. return $this->type;
  27. }
  28. /**
  29. * @return string
  30. */
  31. public function getField(): string {
  32. return $this->field;
  33. }
  34. public function getValue(): string|int|bool|\DateTime|array {
  35. return $this->value;
  36. }
  37. /**
  38. * @return string
  39. * @since 28.0.0
  40. */
  41. public function getExtra(): string {
  42. return $this->extra;
  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 static function escapeLikeParameter(string $param): string {
  51. return addcslashes($param, '\\_%');
  52. }
  53. public function __toString(): string {
  54. return $this->field . ' ' . $this->type . ' ' . json_encode($this->value);
  55. }
  56. }