0

I'm developing a Symfony App and I need to code a helper as a service. First of all I've defined 3 constants as parameters to take them in all web app

This is part of parameters content:

parameters:
    api.public.key: '123456789'
    api.private.key: 'ABCDEFGHI'
    api.timestamp: '1'

Now I'm going to develope my custom helper Utils/ApiHelper.php but I need that my helper can recieve this 3 parameters.

I've my Helper defined my helper as service like this:

services:
    api.helper:
        class: AppBundle\Utils\ApiHelper
        public: true

1 Answer 1

1

You can add arguments to your custom service:

services:
    api.helper:
        class: AppBundle\Utils\ApiHelper
        public: true
        arguments: ['%api.public.key%', '%api.private.key%', '%api.timestamp%']

And then pass it as constructor arguments:

class ApiHelper
{
    // ...
    public function __construct(string $publicKey, string $privateKey, string $timeStamp)
    {
        // ...
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.