Rearrange structure

This commit is contained in:
Sobuno
2025-01-02 22:17:56 +01:00
parent 78f9f7e2dd
commit afc9ea08f3
9 changed files with 143 additions and 129 deletions

View File

@@ -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;

View 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;
}
}

View File

@@ -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;

View 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;
}
}

View File

@@ -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

View 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;
}

View 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)) . ')';
}
}

View 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;
}
}

View File

@@ -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)) . ')';
}
}