1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\ODM\MongoDB\Aggregation\Stage; |
4
|
|
|
|
5
|
|
|
use Doctrine\ODM\MongoDB\Aggregation\Expr; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Fluent interface for adding a $project stage to an aggregation pipeline. |
9
|
|
|
* |
10
|
|
|
* @author alcaeus <[email protected]> |
11
|
|
|
* @since 1.2 |
12
|
|
|
*/ |
13
|
|
|
class Project extends Operator |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
11 |
|
public function getExpression() |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
11 |
|
'$project' => $this->expr->getExpression() |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the average value of the numeric values that result from applying |
27
|
|
|
* a specified expression to each document in a group of documents that |
28
|
|
|
* share the same group by key. Ignores nun-numeric values. |
29
|
|
|
* |
30
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/ |
31
|
|
|
* @see Expr::avg |
32
|
|
|
* @param mixed|Expr $expression1 |
33
|
|
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
34
|
|
|
* @return $this |
35
|
|
|
* |
36
|
|
|
* @since 1.3 |
37
|
|
|
*/ |
38
|
2 |
|
public function avg($expression1/* , $expression2, ... */) |
39
|
|
|
{ |
40
|
2 |
|
$this->expr->avg(func_num_args() === 1 ? $expression1 : func_get_args()); |
41
|
|
|
|
42
|
2 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Shorthand method to define which fields to be included. |
47
|
|
|
* |
48
|
|
|
* @param array $fields |
49
|
|
|
* @return $this |
50
|
|
|
*/ |
51
|
|
|
public function includeFields(array $fields) |
52
|
2 |
|
{ |
53
|
|
|
foreach ($fields as $fieldName) { |
54
|
2 |
|
$this->field($fieldName)->expression(true); |
55
|
|
|
} |
56
|
2 |
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Shorthand method to define which fields to be excluded. |
62
|
|
|
* |
63
|
|
|
* If you specify the exclusion of a field other than _id, you cannot employ |
64
|
|
|
* any other $project specification forms. |
65
|
4 |
|
* |
66
|
|
|
* @since 1.5 |
67
|
4 |
|
* @param array $fields |
68
|
4 |
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function excludeFields(array $fields) |
71
|
4 |
|
{ |
72
|
|
|
foreach ($fields as $fieldName) { |
73
|
|
|
$this->field($fieldName)->expression(false); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the highest value that results from applying an expression to |
81
|
|
|
* each document in a group of documents that share the same group by key. |
82
|
|
|
* |
83
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/ |
84
|
2 |
|
* @see Expr::max |
85
|
|
|
* @param mixed|Expr $expression1 |
86
|
2 |
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
87
|
2 |
|
* @return $this |
88
|
|
|
* |
89
|
|
|
* @since 1.3 |
90
|
2 |
|
*/ |
91
|
|
|
public function max($expression1/* , $expression2, ... */) |
92
|
|
|
{ |
93
|
|
|
$this->expr->max(func_num_args() === 1 ? $expression1 : func_get_args()); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the lowest value that results from applying an expression to each |
100
|
|
|
* document in a group of documents that share the same group by key. |
101
|
|
|
* |
102
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/ |
103
|
|
|
* @see Expr::min |
104
|
|
|
* @param mixed|Expr $expression1 |
105
|
2 |
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
106
|
|
|
* @return $this |
107
|
2 |
|
* |
108
|
|
|
* @since 1.3 |
109
|
2 |
|
*/ |
110
|
|
|
public function min($expression1/* , $expression2, ... */) |
111
|
|
|
{ |
112
|
|
|
$this->expr->min(func_num_args() === 1 ? $expression1 : func_get_args()); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Calculates the population standard deviation of the input values. |
119
|
|
|
* |
120
|
|
|
* The argument can be any expression as long as it resolves to an array. |
121
|
|
|
* |
122
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/ |
123
|
|
|
* @see Expr::stdDevPop |
124
|
2 |
|
* @param mixed|Expr $expression1 |
125
|
|
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
126
|
2 |
|
* @return $this |
127
|
|
|
* |
128
|
2 |
|
* @since 1.3 |
129
|
|
|
*/ |
130
|
|
|
public function stdDevPop($expression1/* , $expression2, ... */) |
131
|
|
|
{ |
132
|
|
|
$this->expr->stdDevPop(func_num_args() === 1 ? $expression1 : func_get_args()); |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Calculates the sample standard deviation of the input values. |
139
|
|
|
* |
140
|
|
|
* The argument can be any expression as long as it resolves to an array. |
141
|
|
|
* |
142
|
|
|
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/ |
143
|
|
|
* @see Expr::stdDevSamp |
144
|
2 |
|
* @param mixed|Expr $expression1 |
145
|
|
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
146
|
2 |
|
* @return $this |
147
|
|
|
* |
148
|
2 |
|
* @since 1.3 |
149
|
|
|
*/ |
150
|
|
|
public function stdDevSamp($expression1/* , $expression2, ... */) |
151
|
|
|
{ |
152
|
|
|
$this->expr->stdDevSamp(func_num_args() === 1 ? $expression1 : func_get_args()); |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Calculates and returns the sum of all the numeric values that result from |
159
|
|
|
* applying a specified expression to each document in a group of documents |
160
|
|
|
* that share the same group by key. Ignores nun-numeric values. |
161
|
|
|
* |
162
|
|
|
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/ |
163
|
|
|
* @see Expr::sum |
164
|
2 |
|
* @param mixed|Expr $expression1 |
165
|
|
|
* @param mixed|Expr $expression2, ... Additional expressions |
|
|
|
|
166
|
2 |
|
* @return $this |
167
|
|
|
* |
168
|
2 |
|
* @since 1.3 |
169
|
|
|
*/ |
170
|
|
|
public function sum($expression1/* , $expression2, ... */) |
171
|
|
|
{ |
172
|
|
|
$this->expr->sum(func_num_args() === 1 ? $expression1 : func_get_args()); |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.