Created
July 3, 2021 20:48
-
-
Save samijnih/b4b3e68f92e48512b5e88fb7de1c50da to your computer and use it in GitHub Desktop.
Command and handler for creating a recipe.
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); | |
namespace Application\UseCases\Recipes; | |
final class CreateRecipe | |
{ | |
public function __construct( | |
private string $id, | |
private string $name, | |
private array $ingredients, | |
private array $steps, | |
) { | |
} | |
public function getId(): string | |
{ | |
return $this->id; | |
} | |
public function getName(): string | |
{ | |
return $this->name; | |
} | |
public function getIngredients(): array | |
{ | |
return $this->ingredients; | |
} | |
public function getSteps(): array | |
{ | |
return $this->steps; | |
} | |
} |
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); | |
namespace Application\UseCases\Recipes; | |
use Domain\Model\Recipes\Recipe; | |
use Domain\Model\Recipes\Recipe\ValueObject\Ingredients; | |
use Domain\Model\Recipes\Recipe\ValueObject\Name; | |
use Domain\Model\Recipes\Recipe\ValueObject\RecipeId; | |
use Domain\Model\Recipes\Recipe\ValueObject\Steps; | |
use Domain\Model\Recipes\RecipeRepository; | |
final class HandleCreateRecipe | |
{ | |
public function __construct( | |
private RecipeRepository $recipeRepository, | |
) { | |
} | |
public function execute(CreateRecipe $createRecipe): void | |
{ | |
$recipe = Recipe::create( | |
RecipeId::fromString($createRecipe->getId()), | |
Name::fromString($createRecipe->getName()), | |
Ingredients::fromArray($createRecipe->getIngredients()), | |
Steps::fromArray($createRecipe->getSteps()) | |
); | |
$this->recipeRepository->add($recipe); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment