| @@ 16-269 (lines=254) @@ | ||
| 13 | * @author alcaeus <[email protected]> |
|
| 14 | * @since 1.5 |
|
| 15 | */ |
|
| 16 | abstract class AbstractOutput extends Stage |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @var Stage\AbstractBucket |
|
| 20 | */ |
|
| 21 | protected $bucket; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @var Expr |
|
| 25 | */ |
|
| 26 | private $expr; |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @param Builder $builder |
|
| 30 | * @param Stage\AbstractBucket $bucket |
|
| 31 | */ |
|
| 32 | public function __construct(Builder $builder, Stage\AbstractBucket $bucket) |
|
| 33 | { |
|
| 34 | parent::__construct($builder); |
|
| 35 | ||
| 36 | $this->bucket = $bucket; |
|
| 37 | $this->expr = $builder->expr(); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * {@inheritdoc} |
|
| 42 | */ |
|
| 43 | public function getExpression() |
|
| 44 | { |
|
| 45 | return $this->expr->getExpression(); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Returns an array of all unique values that results from applying an |
|
| 50 | * expression to each document in a group of documents that share the same |
|
| 51 | * group by key. Order of the elements in the output array is unspecified. |
|
| 52 | * |
|
| 53 | * AddToSet is an accumulator operation only available in the group stage. |
|
| 54 | * |
|
| 55 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/addToSet/ |
|
| 56 | * @see Expr::addToSet |
|
| 57 | * |
|
| 58 | * @param mixed|Expr $expression |
|
| 59 | * |
|
| 60 | * @return $this |
|
| 61 | */ |
|
| 62 | public function addToSet($expression) |
|
| 63 | { |
|
| 64 | $this->expr->addToSet($expression); |
|
| 65 | ||
| 66 | return $this; |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * Returns the average value of the numeric values that result from applying |
|
| 71 | * a specified expression to each document in a group of documents that |
|
| 72 | * share the same group by key. Ignores nun-numeric values. |
|
| 73 | * |
|
| 74 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/ |
|
| 75 | * @see Expr::avg |
|
| 76 | * |
|
| 77 | * @param mixed|Expr $expression |
|
| 78 | * |
|
| 79 | * @return $this |
|
| 80 | */ |
|
| 81 | public function avg($expression) |
|
| 82 | { |
|
| 83 | $this->expr->avg($expression); |
|
| 84 | ||
| 85 | return $this; |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * Used to use an expression as field value. Can be any expression. |
|
| 90 | * |
|
| 91 | * @see http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-expressions |
|
| 92 | * @see Expr::expression |
|
| 93 | * |
|
| 94 | * @param mixed|Expr $value |
|
| 95 | * |
|
| 96 | * @return $this |
|
| 97 | */ |
|
| 98 | public function expression($value) |
|
| 99 | { |
|
| 100 | $this->expr->expression($value); |
|
| 101 | ||
| 102 | return $this; |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * Set the current field for building the expression. |
|
| 107 | * |
|
| 108 | * @see Expr::field |
|
| 109 | * |
|
| 110 | * @param string $fieldName |
|
| 111 | * |
|
| 112 | * @return $this |
|
| 113 | */ |
|
| 114 | public function field($fieldName) |
|
| 115 | { |
|
| 116 | $this->expr->field($fieldName); |
|
| 117 | ||
| 118 | return $this; |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * Returns the value that results from applying an expression to the first |
|
| 123 | * document in a group of documents that share the same group by key. Only |
|
| 124 | * meaningful when documents are in a defined order. |
|
| 125 | * |
|
| 126 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/first/ |
|
| 127 | * @see Expr::first |
|
| 128 | * |
|
| 129 | * @param mixed|Expr $expression |
|
| 130 | * |
|
| 131 | * @return $this |
|
| 132 | */ |
|
| 133 | public function first($expression) |
|
| 134 | { |
|
| 135 | $this->expr->first($expression); |
|
| 136 | ||
| 137 | return $this; |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * Returns the value that results from applying an expression to the last |
|
| 142 | * document in a group of documents that share the same group by a field. |
|
| 143 | * Only meaningful when documents are in a defined order. |
|
| 144 | * |
|
| 145 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/last/ |
|
| 146 | * @see Expr::last |
|
| 147 | * |
|
| 148 | * @param mixed|Expr $expression |
|
| 149 | * |
|
| 150 | * @return $this |
|
| 151 | */ |
|
| 152 | public function last($expression) |
|
| 153 | { |
|
| 154 | $this->expr->last($expression); |
|
| 155 | ||
| 156 | return $this; |
|
| 157 | } |
|
| 158 | ||
| 159 | /** |
|
| 160 | * Returns the highest value that results from applying an expression to |
|
| 161 | * each document in a group of documents that share the same group by key. |
|
| 162 | * |
|
| 163 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/ |
|
| 164 | * @see Expr::max |
|
| 165 | * |
|
| 166 | * @param mixed|Expr $expression |
|
| 167 | * |
|
| 168 | * @return $this |
|
| 169 | */ |
|
| 170 | public function max($expression) |
|
| 171 | { |
|
| 172 | $this->expr->max($expression); |
|
| 173 | ||
| 174 | return $this; |
|
| 175 | } |
|
| 176 | ||
| 177 | /** |
|
| 178 | * Returns the lowest value that results from applying an expression to each |
|
| 179 | * document in a group of documents that share the same group by key. |
|
| 180 | * |
|
| 181 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/ |
|
| 182 | * @see Expr::min |
|
| 183 | * |
|
| 184 | * @param mixed|Expr $expression |
|
| 185 | * |
|
| 186 | * @return $this |
|
| 187 | */ |
|
| 188 | public function min($expression) |
|
| 189 | { |
|
| 190 | $this->expr->min($expression); |
|
| 191 | ||
| 192 | return $this; |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * Returns an array of all values that result from applying an expression to |
|
| 197 | * each document in a group of documents that share the same group by key. |
|
| 198 | * |
|
| 199 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/push/ |
|
| 200 | * @see Expr::push |
|
| 201 | * |
|
| 202 | * @param mixed|Expr $expression |
|
| 203 | * |
|
| 204 | * @return $this |
|
| 205 | */ |
|
| 206 | public function push($expression) |
|
| 207 | { |
|
| 208 | $this->expr->push($expression); |
|
| 209 | ||
| 210 | return $this; |
|
| 211 | } |
|
| 212 | ||
| 213 | /** |
|
| 214 | * Calculates the population standard deviation of the input values. |
|
| 215 | * |
|
| 216 | * The argument can be any expression as long as it resolves to an array. |
|
| 217 | * |
|
| 218 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/ |
|
| 219 | * @see Expr::stdDevPop |
|
| 220 | * |
|
| 221 | * @param mixed|Expr $expression |
|
| 222 | * |
|
| 223 | * @return $this |
|
| 224 | */ |
|
| 225 | public function stdDevPop($expression) |
|
| 226 | { |
|
| 227 | $this->expr->stdDevPop($expression); |
|
| 228 | ||
| 229 | return $this; |
|
| 230 | } |
|
| 231 | ||
| 232 | /** |
|
| 233 | * Calculates the sample standard deviation of the input values. |
|
| 234 | * |
|
| 235 | * The argument can be any expression as long as it resolves to an array. |
|
| 236 | * |
|
| 237 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/ |
|
| 238 | * @see Expr::stdDevSamp |
|
| 239 | * |
|
| 240 | * @param mixed|Expr $expression |
|
| 241 | * |
|
| 242 | * @return $this |
|
| 243 | */ |
|
| 244 | public function stdDevSamp($expression) |
|
| 245 | { |
|
| 246 | $this->expr->stdDevSamp($expression); |
|
| 247 | ||
| 248 | return $this; |
|
| 249 | } |
|
| 250 | ||
| 251 | /** |
|
| 252 | * Calculates and returns the sum of all the numeric values that result from |
|
| 253 | * applying a specified expression to each document in a group of documents |
|
| 254 | * that share the same group by key. Ignores nun-numeric values. |
|
| 255 | * |
|
| 256 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/ |
|
| 257 | * @see Expr::sum |
|
| 258 | * |
|
| 259 | * @param mixed|Expr $expression |
|
| 260 | * |
|
| 261 | * @return $this |
|
| 262 | */ |
|
| 263 | public function sum($expression) |
|
| 264 | { |
|
| 265 | $this->expr->sum($expression); |
|
| 266 | ||
| 267 | return $this; |
|
| 268 | } |
|
| 269 | } |
|
| 270 | ||
| @@ 31-259 (lines=229) @@ | ||
| 28 | * @author alcaeus <[email protected]> |
|
| 29 | * @since 1.2 |
|
| 30 | */ |
|
| 31 | class Group extends Operator |
|
| 32 | { |
|
| 33 | /** |
|
| 34 | * @var Expr |
|
| 35 | */ |
|
| 36 | protected $expr; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * {@inheritdoc} |
|
| 40 | */ |
|
| 41 | public function __construct(Builder $builder) |
|
| 42 | { |
|
| 43 | parent::__construct($builder); |
|
| 44 | ||
| 45 | $this->expr = $builder->expr(); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@inheritdoc} |
|
| 50 | */ |
|
| 51 | public function getExpression() |
|
| 52 | { |
|
| 53 | return [ |
|
| 54 | '$group' => $this->expr->getExpression() |
|
| 55 | ]; |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Returns an array of all unique values that results from applying an |
|
| 60 | * expression to each document in a group of documents that share the same |
|
| 61 | * group by key. Order of the elements in the output array is unspecified. |
|
| 62 | * |
|
| 63 | * AddToSet is an accumulator operation only available in the group stage. |
|
| 64 | * |
|
| 65 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/addToSet/ |
|
| 66 | * @see Expr::addToSet |
|
| 67 | * @param mixed|Expr $expression |
|
| 68 | * @return $this |
|
| 69 | */ |
|
| 70 | public function addToSet($expression) |
|
| 71 | { |
|
| 72 | $this->expr->addToSet($expression); |
|
| 73 | ||
| 74 | return $this; |
|
| 75 | } |
|
| 76 | ||
| 77 | /** |
|
| 78 | * Returns the average value of the numeric values that result from applying |
|
| 79 | * a specified expression to each document in a group of documents that |
|
| 80 | * share the same group by key. Ignores nun-numeric values. |
|
| 81 | * |
|
| 82 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/ |
|
| 83 | * @see Expr::avg |
|
| 84 | * @param mixed|Expr $expression |
|
| 85 | * @return $this |
|
| 86 | */ |
|
| 87 | public function avg($expression) |
|
| 88 | { |
|
| 89 | $this->expr->avg($expression); |
|
| 90 | ||
| 91 | return $this; |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Used to use an expression as field value. Can be any expression |
|
| 96 | * |
|
| 97 | * @see http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-expressions |
|
| 98 | * @see Expr::expression |
|
| 99 | * @param mixed|Expr $value |
|
| 100 | * @return $this |
|
| 101 | */ |
|
| 102 | public function expression($value) |
|
| 103 | { |
|
| 104 | $this->expr->expression($value); |
|
| 105 | ||
| 106 | return $this; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Set the current field for building the expression. |
|
| 111 | * |
|
| 112 | * @see Expr::field |
|
| 113 | * @param string $fieldName |
|
| 114 | * @return $this |
|
| 115 | */ |
|
| 116 | public function field($fieldName) |
|
| 117 | { |
|
| 118 | $this->expr->field($fieldName); |
|
| 119 | ||
| 120 | return $this; |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * Returns the value that results from applying an expression to the first |
|
| 125 | * document in a group of documents that share the same group by key. Only |
|
| 126 | * meaningful when documents are in a defined order. |
|
| 127 | * |
|
| 128 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/first/ |
|
| 129 | * @see Expr::first |
|
| 130 | * @param mixed|Expr $expression |
|
| 131 | * @return $this |
|
| 132 | */ |
|
| 133 | public function first($expression) |
|
| 134 | { |
|
| 135 | $this->expr->first($expression); |
|
| 136 | ||
| 137 | return $this; |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * Returns the value that results from applying an expression to the last |
|
| 142 | * document in a group of documents that share the same group by a field. |
|
| 143 | * Only meaningful when documents are in a defined order. |
|
| 144 | * |
|
| 145 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/last/ |
|
| 146 | * @see Expr::last |
|
| 147 | * @param mixed|Expr $expression |
|
| 148 | * @return $this |
|
| 149 | */ |
|
| 150 | public function last($expression) |
|
| 151 | { |
|
| 152 | $this->expr->last($expression); |
|
| 153 | ||
| 154 | return $this; |
|
| 155 | } |
|
| 156 | ||
| 157 | /** |
|
| 158 | * Returns the highest value that results from applying an expression to |
|
| 159 | * each document in a group of documents that share the same group by key. |
|
| 160 | * |
|
| 161 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/ |
|
| 162 | * @see Expr::max |
|
| 163 | * @param mixed|Expr $expression |
|
| 164 | * @return $this |
|
| 165 | */ |
|
| 166 | public function max($expression) |
|
| 167 | { |
|
| 168 | $this->expr->max($expression); |
|
| 169 | ||
| 170 | return $this; |
|
| 171 | } |
|
| 172 | ||
| 173 | /** |
|
| 174 | * Returns the lowest value that results from applying an expression to each |
|
| 175 | * document in a group of documents that share the same group by key. |
|
| 176 | * |
|
| 177 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/ |
|
| 178 | * @see Expr::min |
|
| 179 | * @param mixed|Expr $expression |
|
| 180 | * @return $this |
|
| 181 | */ |
|
| 182 | public function min($expression) |
|
| 183 | { |
|
| 184 | $this->expr->min($expression); |
|
| 185 | ||
| 186 | return $this; |
|
| 187 | } |
|
| 188 | ||
| 189 | /** |
|
| 190 | * Returns an array of all values that result from applying an expression to |
|
| 191 | * each document in a group of documents that share the same group by key. |
|
| 192 | * |
|
| 193 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/push/ |
|
| 194 | * @see Expr::push |
|
| 195 | * @param mixed|Expr $expression |
|
| 196 | * @return $this |
|
| 197 | */ |
|
| 198 | public function push($expression) |
|
| 199 | { |
|
| 200 | $this->expr->push($expression); |
|
| 201 | ||
| 202 | return $this; |
|
| 203 | } |
|
| 204 | ||
| 205 | /** |
|
| 206 | * Calculates the population standard deviation of the input values. |
|
| 207 | * |
|
| 208 | * The argument can be any expression as long as it resolves to an array. |
|
| 209 | * |
|
| 210 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/ |
|
| 211 | * @see Expr::stdDevPop |
|
| 212 | * @param mixed|Expr $expression |
|
| 213 | * @return $this |
|
| 214 | * |
|
| 215 | * @since 1.3 |
|
| 216 | */ |
|
| 217 | public function stdDevPop($expression) |
|
| 218 | { |
|
| 219 | $this->expr->stdDevPop($expression); |
|
| 220 | ||
| 221 | return $this; |
|
| 222 | } |
|
| 223 | ||
| 224 | /** |
|
| 225 | * Calculates the sample standard deviation of the input values. |
|
| 226 | * |
|
| 227 | * The argument can be any expression as long as it resolves to an array. |
|
| 228 | * |
|
| 229 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/ |
|
| 230 | * @see Expr::stdDevSamp |
|
| 231 | * @param mixed|Expr $expression |
|
| 232 | * @return $this |
|
| 233 | * |
|
| 234 | * @since 1.3 |
|
| 235 | */ |
|
| 236 | public function stdDevSamp($expression) |
|
| 237 | { |
|
| 238 | $this->expr->stdDevSamp($expression); |
|
| 239 | ||
| 240 | return $this; |
|
| 241 | } |
|
| 242 | ||
| 243 | /** |
|
| 244 | * Calculates and returns the sum of all the numeric values that result from |
|
| 245 | * applying a specified expression to each document in a group of documents |
|
| 246 | * that share the same group by key. Ignores nun-numeric values. |
|
| 247 | * |
|
| 248 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/ |
|
| 249 | * @see Expr::sum |
|
| 250 | * @param mixed|Expr $expression |
|
| 251 | * @return $this |
|
| 252 | */ |
|
| 253 | public function sum($expression) |
|
| 254 | { |
|
| 255 | $this->expr->sum($expression); |
|
| 256 | ||
| 257 | return $this; |
|
| 258 | } |
|
| 259 | } |
|
| 260 | ||