1 | <?php declare(strict_types=1); |
||
22 | class QueryParser { |
||
23 | |||
24 | /** |
||
25 | * DB Driver |
||
26 | * |
||
27 | * @var DriverInterface |
||
28 | */ |
||
29 | private $db; |
||
30 | |||
31 | /** |
||
32 | * Regex patterns for various syntax components |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $matchPatterns = [ |
||
37 | 'function' => '([a-zA-Z0-9_]+\((.*?)\))', |
||
38 | 'identifier' => '([a-zA-Z0-9_-]+\.?)+', |
||
39 | 'operator' => '=|AND|&&?|~|\|\|?|\^|/|>=?|<=?|-|%|OR|\+|NOT|\!=?|<>|XOR' |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * Regex matches |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | public $matches = [ |
||
48 | 'functions' => [], |
||
49 | 'identifiers' => [], |
||
50 | 'operators' => [], |
||
51 | 'combined' => [], |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * Constructor/entry point into parser |
||
56 | * |
||
57 | * @param DriverInterface $db |
||
58 | */ |
||
59 | public function __construct(DriverInterface $db) |
||
63 | |||
64 | /** |
||
65 | * Parser method for setting the parse string |
||
66 | * |
||
67 | * @param string $sql |
||
68 | * @return array |
||
69 | */ |
||
70 | public function parseJoin(string $sql): array |
||
86 | |||
87 | /** |
||
88 | * Compiles a join condition after parsing |
||
89 | * |
||
90 | * @param string $condition |
||
91 | * @return string |
||
92 | */ |
||
93 | public function compileJoin(string $condition): string |
||
109 | |||
110 | /** |
||
111 | * Returns a more useful match array |
||
112 | * |
||
113 | * @param array $array |
||
114 | * @return array |
||
115 | */ |
||
116 | protected function filterArray(array $array): array |
||
127 | } |