/** * @param $object * @return string * @throws InvalidArgumentException */ public function serialize($object) { if ($object instanceof Recipe) { return json_encode($this->recipeConverter->toArray($object)); } throw new InvalidArgumentException(sprintf("Unsupported object \"%s\".", get_class($object))); }
/** * @param Recipe $recipe */ public function indexRecipe(Recipe $recipe) { $params = ['index' => ElasticSearch::INDEX, 'type' => 'recipe', 'id' => $this->slugGenerator->generateFrom((string) $recipe->getName()), 'body' => $this->recipeConverter->toArray($recipe)]; $this->client->index($params); $this->client->indices()->refresh(); }