Skip to content

Instantly share code, notes, and snippets.

@samijnih
Created July 3, 2021 14:08
Show Gist options
  • Save samijnih/b9bd4c22a860f1df9fe3575247ae758b to your computer and use it in GitHub Desktop.
Save samijnih/b9bd4c22a860f1df9fe3575247ae758b to your computer and use it in GitHub Desktop.
An application service for creating a recipe.
<?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