Star
You must be signed in to star a gist
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 | |
final class Basket implements RecordsEvents | |
{ | |
private $basketCanOnlyContainFiveProducts; | |
private function __construct() | |
{ | |
$this->basketCanOnlyContainFiveProducts = new BasketCanOnlyContainFiveProducts(); | |
} | |
private function whenBasketWasPickedUp(BasketWasPickedUp $event) | |
{ | |
$this->basketCanOnlyContainFiveProducts->basketWasPickedUp(); | |
} | |
private function whenProductWasAddedToBasket(ProductWasAddedToBasket $event) | |
{ | |
$this->basketCanOnlyContainFiveProducts->productWasAddedToBasket(); | |
} | |
private function whenProductWasRemovedFromBasket(ProductWasRemovedFromBasket $event) | |
{ | |
$this->basketCanOnlyContainFiveProducts->productWasRemovedFromBasket(); | |
} | |
public static function pickUp(BasketId $basketId) | |
{ | |
$basket = new Basket($basketId); | |
$basket->recordThat(new BasketWasPickedUp($basketId)); | |
return $basket; | |
} | |
public function addProduct(ProductId $productId, $name) | |
{ | |
$this->basketCanOnlyContainFiveProducts->tryToAddProductToBasket(); | |
$this->recordThat( | |
new ProductWasAddedToBasket($this->basketId, $productId, $name) | |
); | |
} | |
public function removeProduct(ProductId $productId) | |
{ | |
$this->recordThat( | |
new ProductWasRemovedFromBasket($this->basketId, $productId) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment