public static function createFromRecipe(Recipe $recipe)
 {
     $command = new UpdateRecipeDescriptionCommand();
     $command->text = $recipe->getDescription()->getText();
     $command->IBAOfficial = $recipe->getDescription()->isOfficialIBA();
     $command->alcoholContent = $recipe->getDescription()->getAlcoholContent();
     $taste = $recipe->getDescription()->getTaste();
     if ($taste->isSweet()) {
         $command->taste[] = Tastes::SWEET;
     }
     if ($taste->isSpicy()) {
         $command->taste[] = Tastes::SPICY;
     }
     if ($taste->isBitter()) {
         $command->taste[] = Tastes::BITTER;
     }
     if ($taste->isSalty()) {
         $command->taste[] = Tastes::SALTY;
     }
     if ($taste->isSour()) {
         $command->taste[] = Tastes::SOUR;
     }
     return $command;
 }
Esempio n. 2
0
 /**
  * @param $recipe
  * @param array $data
  */
 private function deserializeTaste(DomainRecipe $recipe, array $data)
 {
     $tasteBuilder = new TasteBuilder();
     if (array_key_exists('taste', $data)) {
         foreach ($data['taste'] as $tasteName) {
             switch ($tasteName) {
                 case Tastes::SWEET:
                     $tasteBuilder->sweet();
                     break;
                 case Tastes::BITTER:
                     $tasteBuilder->bitter();
                     break;
                 case Tastes::SALTY:
                     $tasteBuilder->salty();
                     break;
                 case Tastes::SPICY:
                     $tasteBuilder->spicy();
                     break;
                 case Tastes::SOUR:
                     $tasteBuilder->sour();
                     break;
             }
         }
     }
     $recipe->getDescription()->changeTaste($tasteBuilder->buildTaste());
 }