| @@ 91-102 (lines=12) @@ | ||
| 88 | * |
|
| 89 | * @throws CompositorException When entity is invalid type. |
|
| 90 | */ |
|
| 91 | public function push(CompositableInterface $entity): DocumentCompositor |
|
| 92 | { |
|
| 93 | //Detaching entity |
|
| 94 | $entity = clone $entity; |
|
| 95 | ||
| 96 | $this->assertSupported($entity); |
|
| 97 | ||
| 98 | $this->entities[] = $entity; |
|
| 99 | $this->atomics['$push'][] = $entity; |
|
| 100 | ||
| 101 | return $this; |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Add entity to set, only one instance of document must be presented. |
|
| @@ 117-131 (lines=15) @@ | ||
| 114 | * |
|
| 115 | * @throws CompositorException When entity is invalid type. |
|
| 116 | */ |
|
| 117 | public function add(CompositableInterface $entity): DocumentCompositor |
|
| 118 | { |
|
| 119 | //Detaching entity |
|
| 120 | $entity = clone $entity; |
|
| 121 | ||
| 122 | $this->assertSupported($entity); |
|
| 123 | ||
| 124 | if (!$this->has($entity)) { |
|
| 125 | $this->entities[] = $entity; |
|
| 126 | } |
|
| 127 | ||
| 128 | $this->atomics['$addToSet'][] = $entity; |
|
| 129 | ||
| 130 | return $this; |
|
| 131 | } |
|
| 132 | ||
| 133 | /** |
|
| 134 | * Pull mathced entities from composition. |
|
| @@ 142-154 (lines=13) @@ | ||
| 139 | * |
|
| 140 | * @return DocumentCompositor |
|
| 141 | */ |
|
| 142 | public function pull(CompositableInterface $entity): DocumentCompositor |
|
| 143 | { |
|
| 144 | //Passing true to get all entity offsets |
|
| 145 | $targets = $this->find($entity, true); |
|
| 146 | ||
| 147 | foreach ($targets as $offset => $target) { |
|
| 148 | unset($this->entities[$offset]); |
|
| 149 | } |
|
| 150 | ||
| 151 | $this->atomics['$pull'][] = clone $entity; |
|
| 152 | ||
| 153 | return $this; |
|
| 154 | } |
|
| 155 | ||
| 156 | /** |
|
| 157 | * Check if composition contains desired document or document matching query. |
|