Last active
August 19, 2019 07:50
-
-
Save nikolaposa/a6cdfee9cdca12e5ef348debd7069bc0 to your computer and use it in GitHub Desktop.
Read model View that additionaly handles events to updates its state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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