| 1 |
Expression Builder |
| 2 |
================== |
| 3 |
|
| 4 |
The Expression Builder is a convenient fluent interface for |
| 5 |
building expressions to be used with the ``Doctrine\Common\Collections\Criteria`` |
| 6 |
class: |
| 7 |
|
| 8 |
.. code-block:: php |
| 9 |
$expressionBuilder = Criteria::expr(); |
| 10 |
|
| 11 |
$criteria = new Criteria(); |
| 12 |
$criteria->where($expressionBuilder->eq('name', 'jwage')); |
| 13 |
$criteria->orWhere($expressionBuilder->eq('name', 'romanb')); |
| 14 |
|
| 15 |
$collection->matching($criteria); |
| 16 |
|
| 17 |
The ``ExpressionBuilder`` has the following API: |
| 18 |
|
| 19 |
andX |
| 20 |
---- |
| 21 |
|
| 22 |
.. code-block:: php |
| 23 |
$expressionBuilder = Criteria::expr(); |
| 24 |
|
| 25 |
$expression = $expressionBuilder->andX( |
| 26 |
$expressionBuilder->eq('foo', 1), |
| 27 |
$expressionBuilder->eq('bar', 1) |
| 28 |
); |
| 29 |
|
| 30 |
$collection->matching(new Criteria($expression)); |
| 31 |
|
| 32 |
orX |
| 33 |
--- |
| 34 |
|
| 35 |
.. code-block:: php |
| 36 |
$expressionBuilder = Criteria::expr(); |
| 37 |
|
| 38 |
$expression = $expressionBuilder->orX( |
| 39 |
$expressionBuilder->eq('foo', 1), |
| 40 |
$expressionBuilder->eq('bar', 1) |
| 41 |
); |
| 42 |
|
| 43 |
$collection->matching(new Criteria($expression)); |
| 44 |
|
| 45 |
not |
| 46 |
--- |
| 47 |
|
| 48 |
.. code-block:: php |
| 49 |
$expressionBuilder = Criteria::expr(); |
| 50 |
|
| 51 |
$expression = $expressionBuilder->not( |
| 52 |
$expressionBuilder->eq('foo', 1) |
| 53 |
); |
| 54 |
|
| 55 |
$collection->matching(new Criteria($expression)); |
| 56 |
|
| 57 |
eq |
| 58 |
--- |
| 59 |
|
| 60 |
.. code-block:: php |
| 61 |
$expressionBuilder = Criteria::expr(); |
| 62 |
|
| 63 |
$expression = $expressionBuilder->eq('foo', 1); |
| 64 |
|
| 65 |
$collection->matching(new Criteria($expression)); |
| 66 |
|
| 67 |
gt |
| 68 |
--- |
| 69 |
|
| 70 |
.. code-block:: php |
| 71 |
$expressionBuilder = Criteria::expr(); |
| 72 |
|
| 73 |
$expression = $expressionBuilder->gt('foo', 1); |
| 74 |
|
| 75 |
$collection->matching(new Criteria($expression)); |
| 76 |
|
| 77 |
lt |
| 78 |
--- |
| 79 |
|
| 80 |
.. code-block:: php |
| 81 |
$expressionBuilder = Criteria::expr(); |
| 82 |
|
| 83 |
$expression = $expressionBuilder->lt('foo', 1); |
| 84 |
|
| 85 |
$collection->matching(new Criteria($expression)); |
| 86 |
|
| 87 |
gte |
| 88 |
--- |
| 89 |
|
| 90 |
.. code-block:: php |
| 91 |
$expressionBuilder = Criteria::expr(); |
| 92 |
|
| 93 |
$expression = $expressionBuilder->gte('foo', 1); |
| 94 |
|
| 95 |
$collection->matching(new Criteria($expression)); |
| 96 |
|
| 97 |
lte |
| 98 |
--- |
| 99 |
|
| 100 |
.. code-block:: php |
| 101 |
$expressionBuilder = Criteria::expr(); |
| 102 |
|
| 103 |
$expression = $expressionBuilder->lte('foo', 1); |
| 104 |
|
| 105 |
$collection->matching(new Criteria($expression)); |
| 106 |
|
| 107 |
neq |
| 108 |
--- |
| 109 |
|
| 110 |
.. code-block:: php |
| 111 |
$expressionBuilder = Criteria::expr(); |
| 112 |
|
| 113 |
$expression = $expressionBuilder->neq('foo', 1); |
| 114 |
|
| 115 |
$collection->matching(new Criteria($expression)); |
| 116 |
|
| 117 |
isNull |
| 118 |
------ |
| 119 |
|
| 120 |
.. code-block:: php |
| 121 |
$expressionBuilder = Criteria::expr(); |
| 122 |
|
| 123 |
$expression = $expressionBuilder->isNull('foo'); |
| 124 |
|
| 125 |
$collection->matching(new Criteria($expression)); |
| 126 |
|
| 127 |
isNotNull |
| 128 |
--------- |
| 129 |
|
| 130 |
.. code-block:: php |
| 131 |
$expressionBuilder = Criteria::expr(); |
| 132 |
|
| 133 |
$expression = $expressionBuilder->isNotNull('foo'); |
| 134 |
|
| 135 |
$collection->matching(new Criteria($expression)); |
| 136 |
|
| 137 |
in |
| 138 |
--- |
| 139 |
|
| 140 |
.. code-block:: php |
| 141 |
$expressionBuilder = Criteria::expr(); |
| 142 |
|
| 143 |
$expression = $expressionBuilder->in('foo', ['value1', 'value2']); |
| 144 |
|
| 145 |
$collection->matching(new Criteria($expression)); |
| 146 |
|
| 147 |
notIn |
| 148 |
----- |
| 149 |
|
| 150 |
.. code-block:: php |
| 151 |
$expressionBuilder = Criteria::expr(); |
| 152 |
|
| 153 |
$expression = $expressionBuilder->notIn('foo', ['value1', 'value2']); |
| 154 |
|
| 155 |
$collection->matching(new Criteria($expression)); |
| 156 |
|
| 157 |
contains |
| 158 |
-------- |
| 159 |
|
| 160 |
.. code-block:: php |
| 161 |
$expressionBuilder = Criteria::expr(); |
| 162 |
|
| 163 |
$expression = $expressionBuilder->contains('foo', 'value1'); |
| 164 |
|
| 165 |
$collection->matching(new Criteria($expression)); |
| 166 |
|
| 167 |
memberOf |
| 168 |
-------- |
| 169 |
|
| 170 |
.. code-block:: php |
| 171 |
$expressionBuilder = Criteria::expr(); |
| 172 |
|
| 173 |
$expression = $expressionBuilder->memberOf('foo', ['value1', 'value2']); |
| 174 |
|
| 175 |
$collection->matching(new Criteria($expression)); |
| 176 |
|
| 177 |
startsWith |
| 178 |
---------- |
| 179 |
|
| 180 |
.. code-block:: php |
| 181 |
$expressionBuilder = Criteria::expr(); |
| 182 |
|
| 183 |
$expression = $expressionBuilder->startsWith('foo', 'hello'); |
| 184 |
|
| 185 |
$collection->matching(new Criteria($expression)); |
| 186 |
|
| 187 |
endsWith |
| 188 |
-------- |
| 189 |
|
| 190 |
.. code-block:: php |
| 191 |
$expressionBuilder = Criteria::expr(); |
| 192 |
|
| 193 |
$expression = $expressionBuilder->endsWith('foo', 'world'); |
| 194 |
|
| 195 |
$collection->matching(new Criteria($expression)); |