I have a SearchManager service which can execute search with the specified engine.
// controller
public function searchAction(RequestStack $requestStack, SearchManager $searchManager): Response
{
// code
$engine = new ElasticsearchEngine();
$searchManager->setEngine($engine)->search($requestStack);
// code
}
class SearchManager {
private $engine;
public function __construct(){
}
public function setEngine(EngineInterface $engine)
{
$this->engine = $engine;
return $this->engine;
}
}
class ElasticsearchEngine implement EngineInterface
{
public function search(RequestStack $requestStack)
{
// Here I build the request
$elasticsearchCommand['from'] = 0;
$elasticsearchCommand['size'] = 100;
$elasticsearchCommand['query']['bool']['must'] = ["match_all" => new \stdClass()];
// so on
// To continue building the query I need to parse posted data and get elasticsearch formatted query so I use a class to do that
$formParser = new FormParser($requestStack);
$elasticsearchCommand['query']['bool']['filter']['bool']['filter'] = $formParser->getFormattedQuery();
}
}
In FormParser I need for some reasons some app parameter. But all these class are instantiate explicitly and I can't get benefits from auto wiring. How can access ParameterbarInterface without injecting it where it's not needed ? (cascading injection)