mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-16 09:51:16 +00:00
Rearrange structure
This commit is contained in:
@@ -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;
|
||||
|
36
app/Support/Search/QueryParser/Field.php
Normal file
36
app/Support/Search/QueryParser/Field.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
/**
|
||||
* Represents a field operator with value (e.g. amount:100)
|
||||
*/
|
||||
class Field extends Node
|
||||
{
|
||||
private string $operator;
|
||||
private string $value;
|
||||
|
||||
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 __toString(): string
|
||||
{
|
||||
return ($this->prohibited ? '-' : '') . $this->operator . ':' . $this->value;
|
||||
}
|
||||
}
|
@@ -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;
|
20
app/Support/Search/QueryParser/Node.php
Normal file
20
app/Support/Search/QueryParser/Node.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
/**
|
||||
* Base class for all nodes
|
||||
*/
|
||||
abstract class Node
|
||||
{
|
||||
abstract public function __toString(): string;
|
||||
|
||||
protected bool $prohibited;
|
||||
|
||||
public function isProhibited(): bool
|
||||
{
|
||||
return $this->prohibited;
|
||||
}
|
||||
}
|
@@ -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
|
13
app/Support/Search/QueryParser/QueryParserInterface.php
Normal file
13
app/Support/Search/QueryParser/QueryParserInterface.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
interface QueryParserInterface
|
||||
{
|
||||
/**
|
||||
* @return Node[]
|
||||
*/
|
||||
public function parse(string $query): array;
|
||||
}
|
38
app/Support/Search/QueryParser/Subquery.php
Normal file
38
app/Support/Search/QueryParser/Subquery.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
/**
|
||||
* Represents a subquery (group of nodes)
|
||||
*/
|
||||
class Subquery extends Node
|
||||
{
|
||||
/** @var Node[] */
|
||||
private array $nodes;
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
* @param bool $prohibited
|
||||
*/
|
||||
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 __toString(): string
|
||||
{
|
||||
return ($this->prohibited ? '-' : '') . '(' . implode(' ', array_map(fn($node) => (string)$node, $this->nodes)) . ')';
|
||||
}
|
||||
}
|
29
app/Support/Search/QueryParser/Word.php
Normal file
29
app/Support/Search/QueryParser/Word.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
/**
|
||||
* Represents a word in the search query, meaning either a single-word without spaces or a quote-delimited string
|
||||
*/
|
||||
class Word extends Node
|
||||
{
|
||||
private string $value;
|
||||
|
||||
public function __construct(string $value, bool $prohibited = false)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->prohibited = $prohibited;
|
||||
}
|
||||
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return ($this->prohibited ? '-' : '') . $this->value;
|
||||
}
|
||||
}
|
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search;
|
||||
|
||||
interface QueryParserInterface
|
||||
{
|
||||
/**
|
||||
* @return Node[]
|
||||
*/
|
||||
public function parse(string $query): array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base class for all nodes
|
||||
*/
|
||||
abstract class Node
|
||||
{
|
||||
abstract public function __toString(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a word in the search query
|
||||
*/
|
||||
class Word extends Node
|
||||
{
|
||||
private string $value;
|
||||
private bool $prohibited;
|
||||
|
||||
public function __construct(string $value, bool $prohibited = false)
|
||||
{
|
||||
$this->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)) . ')';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user