LKDevelopment / hetzner-cloud-php-sdk

A PHP SDK for the Hetzner Cloud API
MIT License
104 stars 51 forks source link

Classes should utilize Guzzle\Client instead of Custom GuzzleClient #39

Closed fliespl closed 4 years ago

fliespl commented 4 years ago

Currently models (Network, Subnet) expect to receive GuzzleClient class, which is just used to setup Guzzle\Client using construct. It doesn't have any additional method.

It's making it impossible to use own implementation of a client.

In my case I wanted to add Client which doesn't throw on http_errors:

        $this->apiClient->setHttpClient(new Client([
            'base_uri' => $this->apiClient->getBaseUrl(),
            **'http_errors' => false,**
            'headers' => [
                'Authorization' => 'Bearer ' . $this->apiClient->getApiToken(),
                'Content-Type' => 'application/json',
                'User-Agent' => ((strlen($this->apiClient->getUserAgent()) > 0) ? $this->apiClient->getUserAgent() . ' ' : '') . 'hcloud-php/' . HetznerAPIClient::VERSION,
            ],
        ]));

Unfortunately it will fail:

In Subnet.php line 53:

  Argument 2 passed to LKDev\HetznerCloud\Models\Networks\Subnet::parse() must be an instance of LKDev\HetznerCloud\Clients\GuzzleClient or null, instance of GuzzleHttp\Client given, called in X\vendor\lkdevelopment\hetzner-cloud-php-sdk\src\Models\Networks\Network.php on line 177  
LKaemmerling commented 4 years ago

You can just extend the LKDev\HetznerCloud\Clients\GuzzleClient client.

fliespl commented 4 years ago

I can, but I can't change basic Guzzle Config, since your __construct is not approving any arguments and doesn't pass it to options.

There is no way to add 'http_errors' => false by extending GuzzleClient.

LKaemmerling commented 4 years ago

Got the problem. The constructor of the Network Model has the wrong type.