How to pass an object with a parameter in the Service Container?

Good day!

Faced with a situation when you need to bring an object with a parameter in the service.yaml. Specifically, to implement oauth 2 League AuthorizationServer object must be passed into the method enableGrantType actually the grant, and the DateInterval object by the parameter.

For example
calls:
- method: enableGrantType
arguments:
- '@League\OAuth2\Server\Grant\PasswordGrant'
- ?

The question is how such implementation can be realized using the Symfony Service Container?
April 3rd 20 at 17:34
2 answers
April 3rd 20 at 17:36
Solution
You can: https://symfony.com/doc/current/service_container/...
And you can: https://symfony.com/doc/current/service_container/...
Or even so: https://symfony.com/doc/current/service_container/...

In the first case, to register your DateInterval as a service, the second is to create it inside of Builder/factory.
Thanks for the reply! To factories just came.
For each grant with its own interval. - ima_Schimmel commented on April 3rd 20 at 17:39
April 3rd 20 at 17:38
Solution
If you don't use trikoder/oauth2-bundle

parameters:
 date_interval: 'PT3600S'

services:
date_interval:
 class: DateInterval
arguments:
 - '%date_interval%'

League\OAuth2\Server\AuthorizationServer:
calls:
 - method: enableGrantType
arguments:
 - '@League\OAuth2\Server\Grant\PasswordGrant'
 - '@date_interval'


If you use, this value is configured in the package configuration https://github.com/trikoder/oauth2-bundle/blob/v2....
Thanks for the reply! trikoder/oauth2-bundle don't use it, because it is not compatible with Symfony 4.4. Because of this, variscite and this issue arose.
If you need different settings for each grant, you registers corresponding to the number of services DateInterval? - ima_Schimmel commented on April 3rd 20 at 17:41
@ima_Schimmelalready working

If you need different settings for each grant, you registers corresponding to the number of services DateInterval?


Everything is in your hands, even through ad services, even through the factory. - Rafael_Stiedema commented on April 3rd 20 at 17:44
@Rafael_Stiedema, got it, thanks! - ima_Schimmel commented on April 3rd 20 at 17:47

Find more questions by tags Symfony