1 | <?php |
||
10 | class Parser |
||
11 | { |
||
12 | protected $factory; |
||
13 | |||
14 | 8 | public function __construct(Factory $factory) |
|
15 | { |
||
16 | 8 | $this->factory = $factory; |
|
17 | 8 | } |
|
18 | |||
19 | /** |
||
20 | * Parses a query and returns an ExpressionInterface. |
||
21 | * That’s the core logic of the database. |
||
22 | * |
||
23 | * @param $query |
||
24 | * |
||
25 | * @return ExpressionInterface |
||
26 | */ |
||
27 | 8 | public function parse(array $query) |
|
31 | |||
32 | 8 | protected function parseExpression($element, $path = null) |
|
61 | |||
62 | 6 | protected function parseOperator($operator, $value, $path) |
|
74 | |||
75 | 2 | protected function parseTreeExpression(TreeExpression $expression, $element, $path) |
|
76 | { |
||
77 | 2 | if (!is_array($element)) { |
|
78 | $class = get_class($expression); |
||
79 | throw new \Exception("The `{$class}` element must be an array"); |
||
80 | } |
||
81 | |||
82 | 2 | foreach ($element as $value) { |
|
83 | 2 | $expression->add($this->parseExpression($value, $path)); |
|
84 | 2 | } |
|
85 | |||
86 | 2 | return $expression; |
|
87 | } |
||
88 | |||
89 | 8 | protected function isOperator($key) |
|
93 | } |
||
94 |