Answer the question
In order to leave comments, you need to log in
Symfony, what is the best way to store a class in settings so that its dependencies are loaded?
Good afternoon!
Please tell me, let's say there are a number of classes whose constructors declare properties of different types: repositories, interfaces, other classes, etc. Through the controller, this is all automatically "pulled up". I need to store these classes in a configuration (eg config.yml). How can I make it so that when an instance of a class is created, all its dependencies are "pulled up"?
Class example:
class Handler
{
public function __construct(
TestRepository $testRepository,
EntityManagerInterface $em,
Test Class $testClass
)
{
}
}
Answer the question
In order to leave comments, you need to log in
It’s not very clear from the question, but after discussion in the comments, it became clear that we need a Service Locator
https://symfony.com/doc/6.0/service_container/serv...
App\handler\action\Handler:
arguments: !service_locator
type1: '@App\handler\create\Handler'
type2: '@App\handler\upload\Handler'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question