You can use example below to pass argument value to a class method at runtime with service definition in Symfony.


Example


class MyClass
{
...

public function setClientId(?string $clientId = null)
{
....
}


public function setClientSecret(?string $clientSecret = null)
{
...
}

...
}

services:
app.my_class:
class: MyClass
calls:
- [setClientId, ['%env(CLIENT_ID)%']]
- [setClientSecret, ['%env(CLIENT_SECRET)%']]