kreait / firebase-bundle

A Symfony Bundle for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
135 stars 25 forks source link

Use a proxy ? #59

Closed adpeyre closed 2 months ago

adpeyre commented 3 months ago

Describe the feature you would like to see

Hello,

Could you add the possibility yo use a proxy ? Maybe add a http client config in the bundle configuration ?

Do you already have a solution ?

Ty

adpeyre commented 3 months ago

If you are agree with https://github.com/kreait/firebase-bundle/pull/60 , I could use my own ProjectFactory class to define the proxy.

class ProjectFactory extends \Kreait\Firebase\Symfony\Bundle\DependencyInjection\Factory\ProjectFactory
{
    public function createFactory(array $config = []): Factory
    {
        $factory = parent::createFactory($config);

        $httpClientOptions = HttpClientOptions::default();
        $httpClientOptions = $httpClientOptions->withGuzzleConfigOptions([
            'proxy' => 'http://proxy',
        ]);

        return $factory->withHttpClientOptions($httpClientOptions);
    }
}
adpeyre commented 3 months ago

I decided not to use the bundle. There are some issues and I can't override configurations. So I used the php sdk only.

I share my config for a messaging usage with an unique client :

    ####
    # Kreait Firebase
    ####
    kreait_firebase.http_config_options:
        class: Kreait\Firebase\Http\HttpClientOptions
        factory: ['Kreait\Firebase\Http\HttpClientOptions', 'default']
        calls:
            - withProxy: !returns_clone ['%env(HDS_HTTP_PROXY)%']

    Kreait\Firebase\Factory:
        calls:
            - withHttpClientOptions: !returns_clone ['@kreait_firebase.http_config_options']
            - withServiceAccount: !returns_clone ['%env(resolve:FIREBASE_CREDENTIALS_PATH)%']
            - withHttpLogger: !returns_clone ['@monolog.logger.firebase']

    Kreait\Firebase\Contract\Messaging:
        factory: ['@Kreait\Firebase\Factory', 'createMessaging']
jeromegamez commented 3 months ago

Good call, that's how I would recommend it anyway - perhaps I should update the README at some point...

Anyway, thanks for sharing, it will certainly be useful to others. I'll keep this and/or the other issue open for the time being, perhaps I can find some time somewhen.

jeromegamez commented 2 months ago

Since you've given an example how to use the SDK without this bundle (again: 👏), and I've merged #60, I'll close this issue now, but feel free to add further comments if you'd like.