P
P
pink2floyd2020-05-26 18:45:59
symfony
pink2floyd, 2020-05-26 18:45:59

How does symfony load classes via input?

For example:


public function createProduct(ValidatorInterface $validator): Response
{
...
}

Where and how are these classes loaded? I read the documentation there, it's a given or maybe I missed it somewhere.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2020-05-26
@pink2floyd

There is a good deal of documentation on this for the Dependency Injection component and the Service Container , which is the central part of this component.
In short, you either describe services manually via configuration (there are several supported formats, including annotations, although they seem to be implemented by an external package) or take advantage of autowiring 'a, leaving Symfony to describe everything for you (using compiler passes , if would need). Actually, the main "magic" of converting all data sources into a bunch of compiled PHP is just in the compiler passes, there are a lot of them and you can write your own.
Since in your example - controller's action - here all the magic is implemented through the processing of the tag controller.service_arguments, which by default is added to all controllers in the services config.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question