2017-02-02 12:19:16 -05:00
|
|
|
<?php
|
2023-11-07 08:43:01 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2017-02-02 12:19:16 -05:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-02-02 12:19:16 -05:00
|
|
|
*/
|
|
|
|
|
namespace OC\Files\Search;
|
|
|
|
|
|
|
|
|
|
use OCP\Files\Search\ISearchComparison;
|
|
|
|
|
|
2024-02-06 04:59:17 -05:00
|
|
|
/**
|
|
|
|
|
* @psalm-import-type ParamValue from ISearchComparison
|
|
|
|
|
*/
|
2017-02-02 12:19:16 -05:00
|
|
|
class SearchComparison implements ISearchComparison {
|
2023-11-06 20:21:29 -05:00
|
|
|
private array $hints = [];
|
2017-02-02 12:19:16 -05:00
|
|
|
|
2023-11-06 20:21:29 -05:00
|
|
|
public function __construct(
|
|
|
|
|
private string $type,
|
|
|
|
|
private string $field,
|
2024-02-06 04:59:17 -05:00
|
|
|
/** @var ParamValue $value */
|
2023-09-21 07:49:16 -04:00
|
|
|
private \DateTime|int|string|bool|array $value,
|
2023-11-06 20:21:29 -05:00
|
|
|
private string $extra = ''
|
|
|
|
|
) {
|
2017-02-02 12:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-11-07 08:43:01 -05:00
|
|
|
public function getType(): string {
|
2017-02-02 12:19:16 -05:00
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-11-07 08:43:01 -05:00
|
|
|
public function getField(): string {
|
2017-02-02 12:19:16 -05:00
|
|
|
return $this->field;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 07:49:16 -04:00
|
|
|
public function getValue(): string|int|bool|\DateTime|array {
|
2017-02-02 12:19:16 -05:00
|
|
|
return $this->value;
|
|
|
|
|
}
|
2021-08-23 09:01:03 -04:00
|
|
|
|
2023-11-07 08:43:01 -05:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-11-06 20:21:29 -05:00
|
|
|
public function getExtra(): string {
|
|
|
|
|
return $this->extra;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 09:01:03 -04:00
|
|
|
public function getQueryHint(string $name, $default) {
|
|
|
|
|
return $this->hints[$name] ?? $default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setQueryHint(string $name, $value): void {
|
|
|
|
|
$this->hints[$name] = $value;
|
|
|
|
|
}
|
2022-11-02 07:44:51 -04:00
|
|
|
|
|
|
|
|
public static function escapeLikeParameter(string $param): string {
|
|
|
|
|
return addcslashes($param, '\\_%');
|
|
|
|
|
}
|
2023-09-21 07:49:16 -04:00
|
|
|
|
|
|
|
|
public function __toString(): string {
|
|
|
|
|
return $this->field . ' ' . $this->type . ' ' . json_encode($this->value);
|
|
|
|
|
}
|
2017-02-02 12:19:16 -05:00
|
|
|
}
|