8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

Add option to create lazy clients #193

Closed gregurco closed 6 years ago

gregurco commented 6 years ago

For now we create service per each client and all these clients are not lazy. This functionality appeared in Symfony 2.3: http://symfony.com/doc/master/service_container/lazy_services.html

So, I propose to add option to define client (and the service as a result) lazy.

eight_points_guzzle:
    # (de)activate logging/profiler; default: %kernel.debug%
    logging: true

    clients:
        api_payment:
            base_url: "http://api.domain.tld"
            lazy: true # default: false

In this case client service will be instantiated as ProxyClass and Client class will be instantiated when it will be called. In some cases it can reduce the memory consumption and give more options to users of bundle.