|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\Query; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Utility class for merging query criteria. |
|
24
|
|
|
* |
|
25
|
|
|
* This is mainly used to incorporate filter and ReferenceMany mapping criteria |
|
26
|
|
|
* into a query. Each criteria array will be joined with "$and" to avoid cases |
|
27
|
|
|
* where criteria might be inadvertently overridden with array_merge(). |
|
28
|
|
|
*/ |
|
29
|
|
|
class CriteriaMerger |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Combines any number of criteria arrays as clauses of an "$and" query. |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $criteria,... Any number of query criteria arrays |
|
|
|
|
|
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
66 |
|
public function merge(/* array($field => $value), ... */) |
|
38
|
|
|
{ |
|
39
|
66 |
|
$criteria = array_filter(func_get_args()); |
|
40
|
|
|
|
|
41
|
66 |
|
if ($criteria) { |
|
|
|
|
|
|
42
|
65 |
|
if (count($criteria) === 1) { |
|
43
|
60 |
|
return $criteria[0]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return [ |
|
47
|
|
|
'$and' => $criteria |
|
48
|
20 |
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
9 |
|
return []; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.