| @@ 97-111 (lines=15) @@ | ||
| 94 | * |
|
| 95 | * @return self|$this |
|
| 96 | */ |
|
| 97 | public function add($value): AbstractArray |
|
| 98 | { |
|
| 99 | $value = $this->filterValue($value); |
|
| 100 | if (is_null($value)) { |
|
| 101 | return $this; |
|
| 102 | } |
|
| 103 | ||
| 104 | if (!in_array($value, $this->values)) { |
|
| 105 | array_push($this->values, $value); |
|
| 106 | } |
|
| 107 | ||
| 108 | $this->atomics['$addToSet']['$each'][] = $value; |
|
| 109 | ||
| 110 | return $this; |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * Alias for atomic operation $pull. Only values passed type filter will be added. |
|
| @@ 120-135 (lines=16) @@ | ||
| 117 | * |
|
| 118 | * @return self|$this |
|
| 119 | */ |
|
| 120 | public function pull($value): AbstractArray |
|
| 121 | { |
|
| 122 | $value = $this->filterValue($value); |
|
| 123 | if (is_null($value)) { |
|
| 124 | return $this; |
|
| 125 | } |
|
| 126 | ||
| 127 | //Removing values from array (non strict) |
|
| 128 | $this->values = array_filter($this->values, function ($item) use ($value) { |
|
| 129 | return $item != $value; |
|
| 130 | }); |
|
| 131 | ||
| 132 | $this->atomics['$pull']['$in'][] = $value; |
|
| 133 | ||
| 134 | return $this; |
|
| 135 | } |
|
| 136 | ||
| 137 | /** |
|
| 138 | * {@inheritdoc} |
|