SearchComparison.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @author Maxence Lange <maxence@artificial-owl.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Files\Search;
  26. use OCP\Files\Search\ISearchComparison;
  27. /**
  28. * @psalm-import-type ParamValue from ISearchComparison
  29. */
  30. class SearchComparison implements ISearchComparison {
  31. private array $hints = [];
  32. public function __construct(
  33. private string $type,
  34. private string $field,
  35. /** @var ParamValue $value */
  36. private \DateTime|int|string|bool|array $value,
  37. private string $extra = ''
  38. ) {
  39. }
  40. /**
  41. * @return string
  42. */
  43. public function getType(): string {
  44. return $this->type;
  45. }
  46. /**
  47. * @return string
  48. */
  49. public function getField(): string {
  50. return $this->field;
  51. }
  52. public function getValue(): string|int|bool|\DateTime|array {
  53. return $this->value;
  54. }
  55. /**
  56. * @return string
  57. * @since 28.0.0
  58. */
  59. public function getExtra(): string {
  60. return $this->extra;
  61. }
  62. public function getQueryHint(string $name, $default) {
  63. return $this->hints[$name] ?? $default;
  64. }
  65. public function setQueryHint(string $name, $value): void {
  66. $this->hints[$name] = $value;
  67. }
  68. public static function escapeLikeParameter(string $param): string {
  69. return addcslashes($param, '\\_%');
  70. }
  71. public function __toString(): string {
  72. return $this->field . ' ' . $this->type . ' ' . json_encode($this->value);
  73. }
  74. }