Skip to content

Commit 405a167

Browse files
authored
Custom destroy attributes (#23)
1 parent 4770e96 commit 405a167

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

src/Integration/Laravel/Contracts/SyncableModel.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,42 @@
77
interface SyncableModel
88
{
99
/**
10-
* @var string
10+
* @return string
1111
*/
1212
public function getKeyName();
1313

1414
/**
15-
* @var string
15+
* @return string
1616
*/
1717
public function getKey();
1818

1919
/**
20-
* @var static|null
20+
* @return static|null
2121
*/
2222
public function fresh();
2323

2424
/**
25-
* @var array
25+
* @return array
2626
*/
2727
public function getTableSyncableAttributes();
2828

2929
/**
30-
* @var string
30+
* @return array
31+
*/
32+
public function getTableSyncableDestroyAttributes();
33+
34+
/**
35+
* @return string
3136
*/
3237
public function classForSync();
3338

3439
/**
35-
* @var bool
40+
* @return bool
3641
*/
3742
public function exists();
3843

3944
/**
40-
* @var string
45+
* @return string
4146
*/
4247
public function routingKey();
4348
}

src/Integration/Laravel/Syncer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ private function syncTable(SyncableModel $model, string $event): void
4848

4949
private function getSyncableAttributes(SyncableModel $model): array
5050
{
51-
if (!$model->exists()) {
52-
return $this->pkAttributes($model);
53-
}
51+
$syncableAttributes = $model->exists() ?
52+
$model->getTableSyncableAttributes() :
53+
$model->getTableSyncableDestroyAttributes();
5454

55-
return array_merge($this->pkAttributes($model), $model->getTableSyncableAttributes());
55+
return array_merge($this->pkAttributes($model), $syncableAttributes);
5656
}
5757

5858
private function needsPublishAttributes(SyncableModel $model, array $attributes): bool

src/Integration/Laravel/TableSyncable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function getTableSyncableAttributes(): array
2020
return $this->getAttributes();
2121
}
2222

23+
public function getTableSyncableDestroyAttributes(): array
24+
{
25+
return [];
26+
}
27+
2328
public function classForSync(): string
2429
{
2530
return static::class;

tests/functional/Laravel/Integration/Publishers/EnsureConsistencyPublisherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function setUp(): void
2424
{
2525
parent::setUp();
2626

27-
$this->spyPublisher = $this->makeSpyPublsiher();
27+
$this->spyPublisher = $this->makeSpyPublisher();
2828

2929
$this->app->bind(Publisher::class, function () {
3030
return $this->spyPublisher;

tests/functional/Laravel/Integration/TableSyncObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function setUp(): void
2222
{
2323
parent::setUp();
2424

25-
$this->spyPublisher = $this->makeSpyPublsiher();
25+
$this->spyPublisher = $this->makeSpyPublisher();
2626

2727
$this->app->bind(Publisher::class, function () {
2828
return $this->spyPublisher;

tests/functional/Laravel/Traits/SpyPublisher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
trait SpyPublisher
1111
{
12-
protected function makeSpyPublsiher(): Publisher
12+
protected function makeSpyPublisher(): Publisher
1313
{
1414
return new class() implements Publisher {
1515
public $messages;

0 commit comments

Comments
 (0)