Created
July 3, 2021 14:08
-
-
Save samijnih/b9bd4c22a860f1df9fe3575247ae758b to your computer and use it in GitHub Desktop.
An application service 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; | |
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 CreateRecipeService | |
{ | |
public function __construct( | |
private RecipeRepository $recipeRepository, | |
) { | |
} | |
public function execute( | |
string $id, | |
string $name, | |
array $ingredients, | |
array $steps, | |
): void { | |
$recipe = Recipe::create( | |
RecipeId::fromString($id), | |
Name::fromString($name), | |
Ingredients::fromArray($ingredients), | |
Steps::fromArray($steps) | |
); | |
$this->recipeRepository->add($recipe); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment