@validator is an interface.
It does not make sense. If it is an interface, there cannot be an instacne Validator service. Yes, it implements ValidatorInterface , but it is not.
On the other hand, I'm sure you will get an instance of RecursiveValidator . See my analyzes:
Check the Validator definition in Symfony XML:
<service id="validator" class="Symfony\Component\Validator\Validator\ValidatorInterface"> <factory service="validator.builder" method="getValidator" /> </service>
Check the validator.builder factory service validator.builder :
<service id="validator.builder" class="Symfony\Component\Validator\ValidatorBuilderInterface"> <factory class="Symfony\Component\Validator\Validation" method="createValidatorBuilder" /> <call method="setConstraintValidatorFactory"> <argument type="service" id="validator.validator_factory" /> </call> <call method="setTranslator"> <argument type="service" id="translator" /> </call> <call method="setTranslationDomain"> <argument>%validator.translation_domain%</argument> </call> </service>
Check out the factory Symfony\Component\Validator\Validation::createValidatorBuilder . It returns an instance of ValidatorBuilder
Finally, check out ValidatorBuilder::getValidator() . It ends with the following:
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
So, you will get the correct instance ( RecursiveValidator ).
Hope this helps ...
source share