diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 596aedd7d0..4e9408a3a8 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -39,6 +39,11 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface; +use FireflyIII\Support\Search\QueryParser\QueryParserInterface; +use FireflyIII\Support\Search\QueryParser\Node; +use FireflyIII\Support\Search\QueryParser\Field; +use FireflyIII\Support\Search\QueryParser\Word; +use FireflyIII\Support\Search\QueryParser\Subquery; use FireflyIII\Support\ParseDateString; use FireflyIII\User; use Illuminate\Pagination\LengthAwarePaginator; diff --git a/app/Support/Search/QueryParser/Field.php b/app/Support/Search/QueryParser/Field.php new file mode 100644 index 0000000000..3028af9730 --- /dev/null +++ b/app/Support/Search/QueryParser/Field.php @@ -0,0 +1,36 @@ +operator = $operator; + $this->value = $value; + $this->prohibited = $prohibited; + } + + public function getOperator(): string + { + return $this->operator; + } + + public function getValue(): string + { + return $this->value; + } + + public function __toString(): string + { + return ($this->prohibited ? '-' : '') . $this->operator . ':' . $this->value; + } +} diff --git a/app/Support/Search/GdbotsQueryParser.php b/app/Support/Search/QueryParser/GdbotsQueryParser.php similarity index 98% rename from app/Support/Search/GdbotsQueryParser.php rename to app/Support/Search/QueryParser/GdbotsQueryParser.php index c8249c455a..8a56d0f6de 100644 --- a/app/Support/Search/GdbotsQueryParser.php +++ b/app/Support/Search/QueryParser/GdbotsQueryParser.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\Support\Search; +namespace FireflyIII\Support\Search\QueryParser; use FireflyIII\Exceptions\FireflyException; use Gdbots\QueryParser\QueryParser as BaseQueryParser; diff --git a/app/Support/Search/QueryParser/Node.php b/app/Support/Search/QueryParser/Node.php new file mode 100644 index 0000000000..7dced2e759 --- /dev/null +++ b/app/Support/Search/QueryParser/Node.php @@ -0,0 +1,20 @@ +prohibited; + } +} diff --git a/app/Support/Search/QueryParser.php b/app/Support/Search/QueryParser/QueryParser.php similarity index 99% rename from app/Support/Search/QueryParser.php rename to app/Support/Search/QueryParser/QueryParser.php index 19a1c678ca..1d7f0658c9 100644 --- a/app/Support/Search/QueryParser.php +++ b/app/Support/Search/QueryParser/QueryParser.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\Support\Search; +namespace FireflyIII\Support\Search\QueryParser; /** * Represents a result from parsing a query node diff --git a/app/Support/Search/QueryParser/QueryParserInterface.php b/app/Support/Search/QueryParser/QueryParserInterface.php new file mode 100644 index 0000000000..831baf1270 --- /dev/null +++ b/app/Support/Search/QueryParser/QueryParserInterface.php @@ -0,0 +1,13 @@ +nodes = $nodes; + $this->prohibited = $prohibited; + } + + /** + * @return Node[] + */ + public function getNodes(): array + { + return $this->nodes; + } + + + public function __toString(): string + { + return ($this->prohibited ? '-' : '') . '(' . implode(' ', array_map(fn($node) => (string)$node, $this->nodes)) . ')'; + } +} diff --git a/app/Support/Search/QueryParser/Word.php b/app/Support/Search/QueryParser/Word.php new file mode 100644 index 0000000000..d7c12b6976 --- /dev/null +++ b/app/Support/Search/QueryParser/Word.php @@ -0,0 +1,29 @@ +value = $value; + $this->prohibited = $prohibited; + } + + public function getValue(): string + { + return $this->value; + } + + public function __toString(): string + { + return ($this->prohibited ? '-' : '') . $this->value; + } +} diff --git a/app/Support/Search/QueryParserInterface.php b/app/Support/Search/QueryParserInterface.php deleted file mode 100644 index 93f88d1e75..0000000000 --- a/app/Support/Search/QueryParserInterface.php +++ /dev/null @@ -1,127 +0,0 @@ -value = $value; - $this->prohibited = $prohibited; - } - - public function getValue(): string - { - return $this->value; - } - - public function isProhibited(): bool - { - return $this->prohibited; - } - - public function __toString(): string - { - return ($this->prohibited ? '-' : '') . $this->value; - } -} - -/** - * Represents a field operator with value (e.g. amount:100) - */ -class Field extends Node -{ - private string $operator; - private string $value; - private bool $prohibited; - - public function __construct(string $operator, string $value, bool $prohibited = false) - { - $this->operator = $operator; - $this->value = $value; - $this->prohibited = $prohibited; - } - - public function getOperator(): string - { - return $this->operator; - } - - public function getValue(): string - { - return $this->value; - } - - public function isProhibited(): bool - { - return $this->prohibited; - } - - public function __toString(): string - { - return ($this->prohibited ? '-' : '') . $this->operator . ':' . $this->value; - } -} - -/** - * Represents a subquery (group of nodes) - */ -class Subquery extends Node -{ - /** @var Node[] */ - private array $nodes; - - private bool $prohibited; - - /** - * @param Node[] $nodes - */ - public function __construct(array $nodes, bool $prohibited = false) - { - $this->nodes = $nodes; - $this->prohibited = $prohibited; - } - - /** - * @return Node[] - */ - public function getNodes(): array - { - return $this->nodes; - } - - public function isProhibited(): bool - { - return $this->prohibited; - } - - public function __toString(): string - { - return ($this->prohibited ? '-' : '') . '(' . implode(' ', array_map(fn($node) => (string)$node, $this->nodes)) . ')'; - } -}