Skip to content

Commit 87495af

Browse files
committed
added ChangeSet to figure out which entities are new/changed
1 parent fad6d75 commit 87495af

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/Config/Elastic.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ services:
1111
identityMap:
1212
factory: Spameri\Elastic\Model\IdentityMap
1313

14+
changeSet:
15+
factory: Spameri\Elastic\Model\ChangeSet
16+
1417
versionProvider:
1518
factory: Spameri\Elastic\Model\VersionProvider(%version%)
1619

src/Model/ChangeSet.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Model;
4+
5+
class ChangeSet
6+
{
7+
8+
/**
9+
* @var array<string, array<string, bool>>
10+
*/
11+
public array $created = [];
12+
13+
14+
public function markExisting(
15+
object $entity,
16+
): void
17+
{
18+
$this->created[$entity::class][\spl_object_hash($entity)] = true;
19+
}
20+
21+
22+
public function isExisting(
23+
object $entity,
24+
): bool
25+
{
26+
return isset($this->created[$entity::class][\spl_object_hash($entity)]);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)