-
Notifications
You must be signed in to change notification settings - Fork 3
/
Query.php
45 lines (36 loc) · 989 Bytes
/
Query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// This file is part of Bileto.
// Copyright 2022-2024 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace App\SearchEngine;
class Query
{
private string $string = '';
/** @var Query\Condition[] */
private array $conditions = [];
public function addCondition(Query\Condition $condition): void
{
$this->conditions[] = $condition;
}
/** @return Query\Condition[] */
public function getConditions(): array
{
return $this->conditions;
}
public static function fromString(string $queryString): Query
{
if (!$queryString) {
return new self();
}
$tokenizer = new Query\Tokenizer();
$parser = new Query\Parser();
$tokens = $tokenizer->tokenize($queryString);
$query = $parser->parse($tokens);
$query->string = $queryString;
return $query;
}
public function getString(): string
{
return $this->string;
}
}