diff --git a/README.md b/README.md index 973ae22..3c4f9c3 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Alternatively, add these two lines to your composer require section: ```json { "require": { - "nexmo/laravel": "^1.0" + "nexmo/laravel": "^2.0" } } ``` @@ -98,6 +98,30 @@ $router->get('/', function () use ($router) { }); ``` +### Dealing with Guzzle Client issues + +By default, this package uses `nexmo/client`, which includes a Guzzle adapter for accessing +the API. Some other libraries supply their own Guzzle adapter, leading to composer not being +able to resolve a list of dependencies. You may get an error when adding `nexmo/laravel` to +your application because of this. + +The Nexmo client allows you to override the HTTP adapter that is being used. This takes a +bit more configuration, but this package allows you to use `nexmo/client-core` to supply your +own HTTP adapter. + +To do this: + +1. `composer require nexmo/client-core` to install the Core SDK +2. Install your own `httplug`-compatible adapter. For example, to use Symfony's HTTP Client: + 1. `composer require symfony/http-client php-http/message-factory php-http/httplug nyholm/psr7` +3. `composer require nexmo/laravel` to install this package +4. In your `.env` file, add the following configuration: + + NEXMO_HTTP_CLIENT="Symfony\\Component\\HttpClient\\HttplugClient" + +You can now pull the `Nexmo\Client` object from the Laravel Service Container, or use the Facade +provided by this package. + Configuration ------------- diff --git a/composer.json b/composer.json index e0a1c42..dfacef8 100644 --- a/composer.json +++ b/composer.json @@ -15,19 +15,25 @@ "email": "michael.heap@nexmo.com", "role": "Developer", "homepage": "http://twitter.com/mheap" + }, + { + "name": "Chris Tankersley", + "email": "chris.tankersley@nexmo.com", + "role": "Developer", + "homepage": "http://twitter.com/dragonmantank" } ], "support": { "email": "devrel@nexmo.com" }, "require": { - "php": ">=5.6", - "illuminate/support": "^5.2", - "nexmo/client": "^1.0" + "php": "^5.6|^7.1", + "illuminate/support": "^5.2|^6.0", + "nexmo/client": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^5.3", - "orchestra/testbench": "~3.0" + "phpunit/phpunit": "^5.3|~6.0|~8.0", + "orchestra/testbench": "~3.0|^4.0" }, "autoload": { "psr-4": { diff --git a/config/nexmo.php b/config/nexmo.php index 372690e..cf35b31 100644 --- a/config/nexmo.php +++ b/config/nexmo.php @@ -53,5 +53,17 @@ */ 'app' => ['name' => function_exists('env') ? env('NEXMO_APP_NAME', 'NexmoLaravel') : 'NexmoLaravel', - 'version' => function_exists('env') ? env('NEXMO_APP_VERSION', '1.1.2') : '1.1.2'] + 'version' => function_exists('env') ? env('NEXMO_APP_VERSION', '1.1.2') : '1.1.2'], + + /* + |-------------------------------------------------------------------------- + | Client Override + |-------------------------------------------------------------------------- + | + | In the event you need to use this with nexmo/client-core, this can be set + | to provide a custom HTTP client. + | + */ + + 'http_client' => function_exists('env') ? env('NEXMO_HTTP_CLIENT', '') : '', ]; diff --git a/src/NexmoServiceProvider.php b/src/NexmoServiceProvider.php index 46fcabe..a4baf7d 100644 --- a/src/NexmoServiceProvider.php +++ b/src/NexmoServiceProvider.php @@ -137,7 +137,12 @@ protected function createNexmoClient(Config $config) ); } - return new Client($credentials, $options); + $httpClient = null; + if ($this->nexmoConfigHas('http_client')) { + $httpClient = $this->app->make($config->get(('nexmo.http_client'))); + } + + return new Client($credentials, $options, $httpClient); } /**