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