Issues (590)

src/Query/ClauseInterface.php (2 issues)

1
<?php
2
3
namespace Bdf\Prime\Query;
4
5
use Bdf\Prime\Query\Expression\ExpressionInterface;
6
use Doctrine\DBAL\Query\Expression\CompositeExpression;
7
8
/**
9
 * Interface for Clause (base for queries)
10
 */
11
interface ClauseInterface
12
{
13
    /**
14
     * Set custom filters
15
     *
16
     * @param array<string,callable(static,mixed):void> $filters
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,callable(static,mixed):void> at position 4 could not be parsed: Expected '>' at position 4, but found 'callable'.
Loading history...
17
     *
18
     * @return $this
19
     */
20
    public function setCustomFilters(array $filters);
21
22
    /**
23
     * Add a custom filter
24
     *
25
     * @param string $name
26
     * @param callable(static,mixed):void $callback
27
     *
28
     * @return $this
29
     */
30
    public function addCustomFilter(string $name, callable $callback);
31
32
    /**
33
     * Get custom filters
34
     *
35
     * @return array<string,callable(static,mixed):void>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,callable(static,mixed):void> at position 4 could not be parsed: Expected '>' at position 4, but found 'callable'.
Loading history...
36
     */
37
    public function getCustomFilters(): array;
38
39
    /**
40
     * Get clause statement
41
     *
42
     * @param string $statement
43
     *
44
     * @return array
45
     */
46
    public function statement(string $statement): array;
47
48
    /**
49
     * Add clause statement
50
     *
51
     * @param string $name
52
     * @param mixed $values
53
     *
54
     * @return void
55
     */
56
    public function addStatement(string $name, $values): void;
57
58
    /**
59
     * Add a criteria part: WHERE HAVING ON
60
     *
61
     * 2 distinct calls:
62
     *   * without array
63
     *   * with array
64
     *
65
     * <code>
66
     *     $query
67
     *         ->buildClause('where', 'u.id')  // IS NULL shortcut
68
     *         ->buildClause('where', 'u.id', '=', '1') // interpreted expression: will replace by positionnal char
69
     *         ->buildClause('where', 'u.id', '1')  // default operator is '='
70
     *         ->buildClause('where', ['u.id' => '1']);  // send criteria
71
     *         ->buildClause('where', ['u.id =' => '1']);  // send criteria with operator
72
     * </code>
73
     *
74
     * Does not manage expression with ExpressionInterface
75
     * <code>
76
     * // Not working
77
     *     $query->buildClause('where', new Raw('raw expression'));
78
     * // Do
79
     *     $query->buildRaw('where', new Raw('raw expression'));
80
     *     // Or
81
     *     $query->buildRaw('where', 'raw expression');
82
     * </code>
83
     *
84
     * @param string $statement
85
     * @param string|array<string,mixed> $expression The restriction predicates.
86
     * @param string|null|mixed $operator
87
     * @param mixed $value
88
     * @param string $type
89
     *
90
     * @return $this
91
     */
92
    public function buildClause(string $statement, $expression, $operator = null, $value = null, string $type = CompositeExpression::TYPE_AND);
93
94
    /**
95
     * Add a raw expression in statement
96
     *
97
     * <code>
98
     *    $query->buildRaw('where', 'u.id = 2')
99
     * </code>
100
     *
101
     * @param string $statement
102
     * @param string|QueryInterface|ExpressionInterface $expression
103
     * @param string $type
104
     *
105
     * @return $this
106
     */
107
    public function buildRaw(string $statement, $expression, string $type = CompositeExpression::TYPE_AND);
108
109
    /**
110
     * Add nested statement
111
     *
112
     * <code>
113
     *    $query
114
     *         ->buildNested('where', function($query) {
115
     *             ...
116
     *         })
117
     * </code>
118
     *
119
     * @param string $statement
120
     * @param callable(static):void $callback
121
     * @param string $type
122
     *
123
     * @return $this
124
     */
125
    public function buildNested(string $statement, callable $callback, string $type = CompositeExpression::TYPE_AND);
126
127
    /**
128
     * @todo Revoir cette gestion des commandes
129
     *
130
     * Call method from command available in criteria
131
     *
132
     * @param string $command
133
     * @param mixed $value
134
     *
135
     * @return $this This Query instance.
136
     */
137
    public function addCommand(string $command, $value);
138
}
139