diff --git a/README.md b/README.md index 4d1dc22..84dc3ee 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ Clockify API client ==================== -[![Build Status](https://travis-ci.org/jdecool/clockify-api.svg?branch=master)](https://travis-ci.org/jdecool/clockify-api?branch=master) [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fjdecool%2Fclockify-api%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/jdecool/clockify-api/goto?ref=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jdecool/clockify-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jdecool/clockify-api/?branch=master) [![Latest Stable Version](https://poser.pugx.org/jdecool/clockify-api/v/stable.png)](https://packagist.org/packages/jdecool/clockify-api) @@ -10,19 +9,16 @@ PHP client for [Clockify.me API](https://clockify.me/developers-api). ## Install it -Install using [composer](https://getcomposer.org), with guzzle6-adapter: +You need to install the library with a PSR-18 compliant HTTP client. -```bash -composer require jdecool/clockify-api php-http/guzzle6-adapter -``` - -Install using [composer](https://getcomposer.org), with guzzle7-adapter: +Example using Guzzle: ```bash -composer require jdecool/clockify-api php-http/guzzle7-adapter +composer require jdecool/clockify-api guzzlehttp/guzzle http-interop/http-factory-guzzle ``` -The library is decoupled from any HTTP message client with [HTTPlug](http://httplug.io). That's why you need to install a client implementation `http://httplug.io/` in this example. +The library is decoupled from any HTTP message client with [HTTPlug](http://httplug.io). +That's why you need to install a client implementation `http://httplug.io/` in this example. ## Getting started diff --git a/composer.json b/composer.json index 7577c7c..21a73da 100644 --- a/composer.json +++ b/composer.json @@ -10,17 +10,17 @@ } ], "require": { - "php": "^7.2", + "php": "^7.3", "ext-json": "*", "myclabs/php-enum": "^1.7", - "php-http/client-common": "^2.0", - "php-http/client-implementation": "^1.0", - "php-http/discovery": "^1.4", - "php-http/httplug": "^2.0" + "php-http/client-common": "^2.3", + "php-http/discovery": "^1.12", + "php-http/httplug": "^2.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.15", - "php-http/mock-client": "^1.4", + "guzzlehttp/guzzle": "^7.0", + "http-interop/http-factory-guzzle": "^1.0", "phpstan/phpstan": "^0.11.16", "phpunit/phpunit": "^8.0" }, diff --git a/src/ClientBuilder.php b/src/ClientBuilder.php index 2c6f438..299f7d4 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -6,12 +6,13 @@ use Http\Client\{ Common\HttpMethodsClient, - HttpClient + HttpClient, }; use Http\Message\MessageFactory; +use Psr\Http\Message\RequestFactoryInterface; use Http\Discovery\{ - HttpClientDiscovery, - MessageFactoryDiscovery + Psr17FactoryDiscovery, + Psr18ClientDiscovery, }; class ClientBuilder @@ -19,12 +20,12 @@ class ClientBuilder private const ENDPOINT_V1 = 'https://api.clockify.me/api/v1/'; private $httpClient; - private $messageFactory; + private $requestFactory; - public function __construct(?HttpClient $httpClient = null, ?MessageFactory $messageFactory = null) + public function __construct(?HttpClient $httpClient = null, ?RequestFactoryInterface $requestFactory = null) { - $this->httpClient = $httpClient ?? HttpClientDiscovery::find(); - $this->messageFactory = $messageFactory ?? MessageFactoryDiscovery::find(); + $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); + $this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); } public function createClientV1(string $apiKey): Client @@ -34,7 +35,7 @@ public function createClientV1(string $apiKey): Client public function create(string $endpoint, string $apiKey): Client { - $http = new HttpMethodsClient($this->httpClient, $this->messageFactory); + $http = new HttpMethodsClient($this->httpClient, $this->requestFactory); return new Client($http, $endpoint, $apiKey); }