feat(sync) : add DTOs and SyncStrategyInterface
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
13
src/DTO/SyncConfirmation.php
Normal file
13
src/DTO/SyncConfirmation.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\DTO;
|
||||||
|
|
||||||
|
class SyncConfirmation
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly bool $confirmDeletions = false,
|
||||||
|
public readonly bool $confirmTypeChanges = false,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
27
src/DTO/SyncExecutionResult.php
Normal file
27
src/DTO/SyncExecutionResult.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\DTO;
|
||||||
|
|
||||||
|
use JsonSerializable;
|
||||||
|
|
||||||
|
class SyncExecutionResult implements JsonSerializable
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly int $itemsUpdated,
|
||||||
|
public readonly array $additions = [],
|
||||||
|
public readonly array $deletions = [],
|
||||||
|
public readonly array $modifications = [],
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function jsonSerialize(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'itemsUpdated' => $this->itemsUpdated,
|
||||||
|
'additions' => $this->additions,
|
||||||
|
'deletions' => $this->deletions,
|
||||||
|
'modifications' => $this->modifications,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/DTO/SyncPreviewResult.php
Normal file
38
src/DTO/SyncPreviewResult.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\DTO;
|
||||||
|
|
||||||
|
use JsonSerializable;
|
||||||
|
|
||||||
|
class SyncPreviewResult implements JsonSerializable
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly string $modelTypeId,
|
||||||
|
public readonly string $category,
|
||||||
|
public readonly int $itemCount,
|
||||||
|
public readonly array $additions = [],
|
||||||
|
public readonly array $deletions = [],
|
||||||
|
public readonly array $modifications = [],
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function hasImpact(): bool
|
||||||
|
{
|
||||||
|
return array_sum($this->additions) > 0
|
||||||
|
|| array_sum($this->deletions) > 0
|
||||||
|
|| array_sum($this->modifications) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'modelTypeId' => $this->modelTypeId,
|
||||||
|
'category' => $this->category,
|
||||||
|
'itemCount' => $this->itemCount,
|
||||||
|
'additions' => $this->additions,
|
||||||
|
'deletions' => $this->deletions,
|
||||||
|
'modifications' => $this->modifications,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/Service/Sync/SyncStrategyInterface.php
Normal file
27
src/Service/Sync/SyncStrategyInterface.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Sync;
|
||||||
|
|
||||||
|
use App\DTO\SyncConfirmation;
|
||||||
|
use App\DTO\SyncExecutionResult;
|
||||||
|
use App\DTO\SyncPreviewResult;
|
||||||
|
use App\Entity\ModelType;
|
||||||
|
|
||||||
|
interface SyncStrategyInterface
|
||||||
|
{
|
||||||
|
public function supports(ModelType $modelType): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute diff between proposed structure and current items' slots.
|
||||||
|
* Does NOT persist anything.
|
||||||
|
*/
|
||||||
|
public function preview(ModelType $modelType, array $newStructure): SyncPreviewResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply sync: compare current skeleton requirements (already persisted)
|
||||||
|
* with items' slots and add/remove as needed.
|
||||||
|
*/
|
||||||
|
public function execute(ModelType $modelType, SyncConfirmation $confirmation): SyncExecutionResult;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user