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
38 lines
1000 B
PHP
38 lines
1000 B
PHP
<?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;
|
|
}
|
|
}
|