I have a simple controller with two actions. They have different output format so I want to inject different Formatter implementations in action's parameters. Is there a right way to do that?
class ProductController
{
private ProductManager $productManager;
public function __construct(ProductManager $productManager)
{
$this->productManager = $productManager;
}
public function search(Request $request, Formatter $formatter)
{
$query = $request->get('q');
$response = $this->productManager->search($query);
return new JsonResponse($formatter->format($response));
}
public function suggest(Request $request, Formatter $formatter)
{
$query = $request->get('q');
$response = $this->productManager->suggest($query);
return new JsonResponse($formatter->format($response));
}
}