How to provide parameters to service registered outside services.yaml

I am having an issue with Symfony autowiring.
I need to replace one of third party services with my own.
The service is originally defined like this:

    ewz_recaptcha.form.type:
        class: EWZBundleRecaptchaBundleFormTypeEWZRecaptchaType
        public: true
        arguments:
            - '%ewz_recaptcha.public_key%'
            - '%ewz_recaptcha.enabled%'
            - '%ewz_recaptcha.ajax%'
            - '@ewz_recaptcha.locale.resolver'
            - '%ewz_recaptcha.api_host%'
        tags:
            - { name: form.type }

My definition looks similar:

    ewz_recaptcha.form.type:
      class: AppFormTypeEWZRecaptchaType
      public: true
      arguments:
          - ''
          - false
          - '%ewz_recaptcha.ajax%'
          - '@ewz_recaptcha.locale.resolver'
          - '%ewz_recaptcha.api_host%'
      tags:
          - { name: form.type }

I ignore the first 2 parameters since those are loaded later from database (thats the change I did in the service).

Now this works fine if I put it in config/services.yaml
But since in this project I use that file only for project services, and all overwrites I put in third party config files, I tried to move it to config/packages/ewz_recaptcha.yaml

But now I am getting error saying:

Cannot autowire service "AppFormTypeEWZRecaptchaType": argument "$publicKey" of method "EWZBundleRecaptchaBundleFormTypeEWZRecaptchaType::__construct()" has no type-hint, you should configure its value explicitly.

I even hooked into SymfonyComponentDependencyInjectionCompilerAutowirePass to check what is going on, and when defined in services.yaml the $arguments parameter is filled with my arguments, but when moved to ewz_recaptcha.yaml arguments array is empty.

Is there a different way I should define arguments when service is defined outside services.yaml file?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *