Skip to content

Commit 2738f25

Browse files
committed
add clear method to ChangeSet, IdentityMap, and EntityManager classes
1 parent 3af2e36 commit 2738f25

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/EntityManager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,11 @@ public function remove(\Spameri\Elastic\Entity\AbstractElasticEntity $entity): b
233233
return true;
234234
}
235235

236+
237+
public function clear(): void
238+
{
239+
$this->identityMap->clear();
240+
$this->changeSet->clear();
241+
}
242+
236243
}

src/Model/ChangeSet.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ public function isExisting(
2626
return isset($this->created[$entity::class][\spl_object_hash($entity)]);
2727
}
2828

29+
30+
public function clear(): void
31+
{
32+
$this->created = [];
33+
}
34+
2935
}

src/Model/IdentityMap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,13 @@ private function getSerializedString(\Spameri\Elastic\Entity\AbstractElasticEnti
121121
return \md5(\serialize($serializedArray));
122122
}
123123

124+
125+
public function clear(): void
126+
{
127+
$this->identityMap = [];
128+
$this->persisted = [];
129+
$this->creatingEntityList = [];
130+
$this->uninitializedEntityList = [];
131+
}
132+
124133
}

0 commit comments

Comments
 (0)