Answer the question
In order to leave comments, you need to log in
How can a service select the required repository at runtime?
Hey!
I will say that the given code examples are abstract, but help to understand the problem that I encountered.
There is a controller that calls a method on some service:
class ExampleController extends AbstractController
{
public function index(SomeService $service)
{
...
$service->getResult('paramValue');
...
}
}
class SomeService
{
public function getResult(string $param)
{
...
$epics = $this->repository->getData();
...
}
}
interface DataRepository {
public function getData();
}
class RepositoryOne implements DataRepository {
private $external;
public function __construct(ExternalService $external)
{
$this->external = $external;
}
public function getData()
{
...
}
}
class RepositoryTwo implements DataRepository {
private $external;
public function __construct(ExternalService $external)
{
$this->external = $external;
}
public function getData()
{
...
}
}
Answer the question
In order to leave comments, you need to log in
https://github.com/symfony/symfony/blob/6.0/src/Sy...
https://designpatternsphp.readthedocs.io/ru/latest...
Either shift the choice to the repositories themselves, or introduce a new class, who will choose
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question