Step 00 — Squelette + intégration naïve
3 Bounded Contexts (Sales, Invoicing, LegacyFulfillment) avec : - Domaines complets (agrégats, VOs, événements, invariants) - Couche application (commands, queries, ports) - Infrastructure in-memory (repos, gateway fake) - Controllers HTTP Symfony - Couplage naïf synchrone entre BC via NaiveSalesEventPublisher - 20 tests unitaires et d'intégration passants
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Invoicing\Infrastructure\Persistence;
|
||||
|
||||
use MiniShop\Invoicing\Application\Port\InvoiceRepository;
|
||||
use MiniShop\Invoicing\Domain\Model\Invoice;
|
||||
use MiniShop\Invoicing\Domain\Model\InvoiceId;
|
||||
|
||||
final class InMemoryInvoiceRepository implements InvoiceRepository
|
||||
{
|
||||
/** @var array<string, Invoice> */
|
||||
private array $invoices = [];
|
||||
|
||||
public function save(Invoice $invoice): void
|
||||
{
|
||||
$this->invoices[$invoice->id->toString()] = $invoice;
|
||||
}
|
||||
|
||||
public function get(InvoiceId $id): Invoice
|
||||
{
|
||||
return $this->invoices[$id->toString()]
|
||||
?? throw new \RuntimeException(sprintf('Invoice "%s" not found.', $id->toString()));
|
||||
}
|
||||
|
||||
public function findByExternalOrderId(string $externalOrderId): ?Invoice
|
||||
{
|
||||
foreach ($this->invoices as $invoice) {
|
||||
if ($invoice->externalOrderId === $externalOrderId) {
|
||||
return $invoice;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user