I have a problem with my service.
<service id="api.api" class="ApiBundle\Service\ApiService">
<argument type="service" id="request_stack"/>
<argument type="service" id="validator"/>
</service>
The __construct is :
public function __construct(RequestStack $requestStack, RecursiveValidator $validator)
{
$this->request = $requestStack->getCurrentRequest();
$this->validator = $validator;
}
The problem is:
Do you know why I have this conflict ?
In ENV_DEV with RecursiveValidator, I have this error :
Type error: Argument 2 passed to
ApiBundle\Service\ApiService::__construct() must be an instance of
Symfony\Component\Validator\Validator\RecursiveValidator,
instance of Symfony\Component\Validator\Validator\TraceableValidator
given, called in
var/cache/dev/ContainerLqjid6c/getApi_ApiService.php on line 8
cache:clear doesn't solve the problem.
Thank you for your help.
Instead of hinting to an implementation, you should always (if available) hint to an interface. In this case, both RecursiveValidator and TraceableValidator implement the ValidatorInterface.
So your constructor should look like this:
public function __construct(RequestStack $requestStack, ValidatorInterface $validator)
{
$this->request = $requestStack->getCurrentRequest();
$this->validator = $validator;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With