Skip to content

Instantly share code, notes, and snippets.

@nikolaposa
Last active August 19, 2019 07:50
Show Gist options
  • Save nikolaposa/a6cdfee9cdca12e5ef348debd7069bc0 to your computer and use it in GitHub Desktop.
Save nikolaposa/a6cdfee9cdca12e5ef348debd7069bc0 to your computer and use it in GitHub Desktop.
Read model View that additionaly handles events to updates its state
<?php
declare(strict_types=1);
final class PaidOrdersView implements HandlesEvents
{
private $dao;
public function __construct(OrderDao $dao)
{
$this->dao = $dao;
}
public function get(): array
{
return $this->dao->find(['paid' => true]);
}
public function onOrderPaid(OrderPaid $orderPaid): void
{
$orderDto = $this->dao->findById($orderPaid->getOrderId());
$orderDto->paid = true;
$this->dao->update($orderDto);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment