-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClauseInterface.php
More file actions
161 lines (149 loc) · 4.8 KB
/
Copy pathClauseInterface.php
File metadata and controls
161 lines (149 loc) · 4.8 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace Bdf\Prime\Query;
use Bdf\Prime\Query\Expression\ExpressionInterface;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
/**
* Interface for Clause (base for queries)
*/
interface ClauseInterface
{
/**
* Set custom filters
*
* @param array<string,callable(static,mixed):void> $filters
*
* @return $this
*/
public function setCustomFilters(array $filters);
/**
* Add a custom filter
*
* @param string $name
* @param callable(static,mixed):void $callback
*
* @return $this
*/
public function addCustomFilter(string $name, callable $callback);
/**
* Get custom filters
*
* @return array<string,callable(static,mixed):void>
*/
public function getCustomFilters(): array;
/**
* Get clause statement
*
* @param string $statement
*
* @return array
*/
public function statement(string $statement): array;
/**
* Add clause statement
*
* @param string $name
* @param mixed $values
*
* @return void
*/
public function addStatement(string $name, $values): void;
/**
* Add a criteria part: WHERE HAVING ON
*
* 2 distinct calls:
* * without array
* * with array
*
* <code>
* $query
* ->buildClause('where', 'u.id') // IS NULL shortcut
* ->buildClause('where', 'u.id', '=', '1') // interpreted expression: will replace by positionnal char
* ->buildClause('where', 'u.id', '1') // default operator is '='
* ->buildClause('where', ['u.id' => '1']); // send criteria
* ->buildClause('where', ['u.id =' => '1']); // send criteria with operator
* </code>
*
* Does not manage expression with ExpressionInterface
* <code>
* // Not working
* $query->buildClause('where', new Raw('raw expression'));
* // Do
* $query->buildRaw('where', new Raw('raw expression'));
* // Or
* $query->buildRaw('where', 'raw expression');
* </code>
*
* @param string $statement
* @param string|array<string,mixed> $expression The restriction predicates.
* @param string|null|mixed $operator
* @param mixed $value
* @param string $type
*
* @return $this
*/
public function buildClause(string $statement, $expression, $operator = null, $value = null, string $type = CompositeExpression::TYPE_AND);
/**
* Replace a clause value
*
* If the clause does not exist, it will be added
* Only the first statement matching the expression and the operator will be replaced
*
* Note: unlike the buildClause method, this method does not support the array syntax nor nested statements
*
* <code>
* $query->from('users', 'u')->where('u.id', '=', 1); // SELECT * FROM users u WHERE u.id = 1
* $query->replaceClause('where', 'u.id', '=', 2); // Replace the clause : SELECT * FROM users u WHERE u.id = 2
* $query->replaceClause('where', 'u.id', '<', 1000); // Operator is different, so the clause is added : SELECT * FROM users u WHERE u.id = 2 AND u.id < 1000
* </code>
*
* @param string $statement Statement name to modify. e.g. where, having, on...
* @param string $expression Column name or expression
* @param string|mixed|null $operator Comparison operator. If the $value parameter is omitted, this parameter is used as the value, and the operator is set to '='.
* @param mixed $value The value to compare to.
*
* @return $this
*/
public function replaceClause(string $statement, string $expression, $operator = null, $value = null);
/**
* Add a raw expression in statement
*
* <code>
* $query->buildRaw('where', 'u.id = 2')
* </code>
*
* @param string $statement
* @param string|QueryInterface|ExpressionInterface $expression
* @param string $type
*
* @return $this
*/
public function buildRaw(string $statement, $expression, string $type = CompositeExpression::TYPE_AND);
/**
* Add nested statement
*
* <code>
* $query
* ->buildNested('where', function($query) {
* ...
* })
* </code>
*
* @param string $statement
* @param callable(static):void $callback
* @param string $type
*
* @return $this
*/
public function buildNested(string $statement, callable $callback, string $type = CompositeExpression::TYPE_AND);
/**
* @todo Revoir cette gestion des commandes
*
* Call method from command available in criteria
*
* @param string $command
* @param mixed $value
*
* @return $this This Query instance.
*/
public function addCommand(string $command, $value);
}