diff --git a/README.md b/README.md index aec68a969..325158603 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Quick setup 0. Install the PHP SDK with [Composer](https://getcomposer.org/) php composer.phar require launchdarkly/launchdarkly-php - php composer.phar require "guzzlehttp/guzzle:5.*" - php composer.phar require "guzzlehttp/cache-subscriber:0.1.*" + php composer.phar require "guzzlehttp/guzzle:6.2.1" + php composer.phar require "kevinrob/guzzle-cache-middleware": "1.4.1" 1. After installing, require Composer's autoloader: @@ -49,8 +49,8 @@ Using Guzzle To use Guzzle it must be required as a dependency: - php composer.phar require "guzzlehttp/guzzle:5.*" - php composer.phar require "guzzlehttp/cache-subscriber:0.1.*" + php composer.phar require "guzzlehttp/guzzle:6.2.1" + php composer.phar require "kevinrob/guzzle-cache-middleware": "1.4.1" It will then be used as the default way of fetching flags. diff --git a/VERSION b/VERSION index bcaffe19b..afaf360d3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 \ No newline at end of file +1.0.0 \ No newline at end of file diff --git a/composer.json b/composer.json index 4f4d8af27..0329dee7e 100644 --- a/composer.json +++ b/composer.json @@ -17,17 +17,17 @@ "php": ">=5.5" }, "require-dev": { + "guzzlehttp/guzzle": "6.2.1", + "kevinrob/guzzle-cache-middleware": "1.4.1", "phpunit/phpunit": "4.8.26", "phpdocumentor/phpdocumentor": "2.*", "predis/predis": "1.0.*", - "guzzlehttp/guzzle": "5.*", - "guzzlehttp/cache-subscriber": "0.1.*", "zendframework/zend-serializer": "2.7.*" }, "suggested": { - "predis/predis": "1.0.*", - "guzzlehttp/guzzle": "5.*", - "guzzlehttp/cache-subscriber": "0.1.*" + "guzzlehttp/guzzle": "6.2.1", + "kevinrob/guzzle-cache-middleware": "1.4.1", + "predis/predis": "1.0.*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index e0b727b02..87ffb3aaf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "0871703de19487d877517617eb99d4bd", - "content-hash": "b83833be7e74086c2399be31c969a806", + "hash": "cf5c4602f9f9aff086005edc75728d0f", + "content-hash": "f09e942238b22b8ef39b297cd1808ee6", "packages": [], "packages-dev": [ { @@ -221,76 +221,6 @@ ], "time": "2015-08-31 12:32:49" }, - { - "name": "doctrine/cache", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/cache.git", - "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6", - "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6", - "shasum": "" - }, - "require": { - "php": "~5.5|~7.0" - }, - "conflict": { - "doctrine/common": ">2.2,<2.4" - }, - "require-dev": { - "phpunit/phpunit": "~4.8|~5.0", - "predis/predis": "~1.0", - "satooshi/php-coveralls": "~0.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Caching library offering an object-oriented API for many cache backends", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "cache", - "caching" - ], - "time": "2015-12-31 16:37:02" - }, { "name": "doctrine/instantiator", "version": "1.0.5", @@ -438,75 +368,24 @@ ], "time": "2015-10-04 16:44:32" }, - { - "name": "guzzlehttp/cache-subscriber", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/cache-subscriber.git", - "reference": "ecb903f6e11b5ca9f2cdbc460e2e68deea9e8858" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/cache-subscriber/zipball/ecb903f6e11b5ca9f2cdbc460e2e68deea9e8858", - "reference": "ecb903f6e11b5ca9f2cdbc460e2e68deea9e8858", - "shasum": "" - }, - "require": { - "doctrine/cache": "~1.3", - "guzzlehttp/guzzle": "~5.0", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.1-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Subscriber\\Cache\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle HTTP cache subscriber", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "Guzzle", - "cache" - ], - "time": "2014-10-29 21:06:25" - }, { "name": "guzzlehttp/guzzle", - "version": "5.3.0", + "version": "6.2.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "f3c8c22471cb55475105c14769644a49c3262b93" + "reference": "3f808fba627f2c5b69e2501217bf31af349c1427" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f3c8c22471cb55475105c14769644a49c3262b93", - "reference": "f3c8c22471cb55475105c14769644a49c3262b93", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/3f808fba627f2c5b69e2501217bf31af349c1427", + "reference": "3f808fba627f2c5b69e2501217bf31af349c1427", "shasum": "" }, "require": { - "guzzlehttp/ringphp": "^1.1", - "php": ">=5.4.0" + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.3.1", + "php": ">=5.5" }, "require-dev": { "ext-curl": "*", @@ -516,10 +395,13 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "6.2-dev" } }, "autoload": { + "files": [ + "src/functions_include.php" + ], "psr-4": { "GuzzleHttp\\": "src/" } @@ -535,7 +417,7 @@ "homepage": "https://github.com/mtdowling" } ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "description": "Guzzle is a PHP HTTP client library", "homepage": "http://guzzlephp.org/", "keywords": [ "client", @@ -546,44 +428,41 @@ "rest", "web service" ], - "time": "2015-05-20 03:47:55" + "time": "2016-07-15 17:22:37" }, { - "name": "guzzlehttp/ringphp", - "version": "1.1.0", + "name": "guzzlehttp/promises", + "version": "1.2.0", "source": { "type": "git", - "url": "https://github.com/guzzle/RingPHP.git", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" + "url": "https://github.com/guzzle/promises.git", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", "shasum": "" }, "require": { - "guzzlehttp/streams": "~3.0", - "php": ">=5.4.0", - "react/promise": "~2.0" + "php": ">=5.5.0" }, "require-dev": { - "ext-curl": "*", "phpunit/phpunit": "~4.0" }, - "suggest": { - "ext-curl": "Guzzle will use specific adapters if cURL is present" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "1.0-dev" } }, "autoload": { "psr-4": { - "GuzzleHttp\\Ring\\": "src/" - } + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -596,25 +475,32 @@ "homepage": "https://github.com/mtdowling" } ], - "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", - "time": "2015-05-20 03:37:09" + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-05-18 16:56:05" }, { - "name": "guzzlehttp/streams", - "version": "3.0.0", + "name": "guzzlehttp/psr7", + "version": "1.3.1", "source": { "type": "git", - "url": "https://github.com/guzzle/streams.git", - "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + "url": "https://github.com/guzzle/psr7.git", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", - "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" }, "require-dev": { "phpunit/phpunit": "~4.0" @@ -622,13 +508,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { "psr-4": { - "GuzzleHttp\\Stream\\": "src/" - } + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -641,13 +530,14 @@ "homepage": "https://github.com/mtdowling" } ], - "description": "Provides a simple abstraction over streams of data", - "homepage": "http://guzzlephp.org/", + "description": "PSR-7 message implementation", "keywords": [ - "Guzzle", - "stream" + "http", + "message", + "stream", + "uri" ], - "time": "2014-10-12 19:18:40" + "time": "2016-06-24 23:00:38" }, { "name": "herrera-io/json", @@ -992,6 +882,84 @@ ], "time": "2016-01-25 15:43:01" }, + { + "name": "kevinrob/guzzle-cache-middleware", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/Kevinrob/guzzle-cache-middleware.git", + "reference": "f30ded404c296d50820670489d718a04634b6789" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kevinrob/guzzle-cache-middleware/zipball/f30ded404c296d50820670489d718a04634b6789", + "reference": "f30ded404c296d50820670489d718a04634b6789", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "cache/array-adapter": "^0.4", + "doctrine/cache": "^1.0", + "guzzlehttp/guzzle": "^6.0", + "illuminate/cache": "^5.0", + "league/flysystem": "^1.0", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/cache": "^1.0" + }, + "suggest": { + "doctrine/cache": "This library have a lot of ready-to-use cache storage (to be use with Kevinrob\\GuzzleCache\\Storage\\DoctrineCacheStorage)", + "guzzlehttp/guzzle": "For using this library. It was created for Guzzle6. (but you can use it with any PSR-7 HTTP Client)", + "laravel/framework": "To be use with Kevinrob\\GuzzleCache\\Storage\\LaravelCacheStorage", + "league/flysystem": "To be use with Kevinrob\\GuzzleCache\\Storage\\FlysystemStorage", + "psr/cache": "To be use with Kevinrob\\GuzzleCache\\Storage\\Psr6CacheStorage" + }, + "type": "library", + "autoload": { + "psr-4": { + "Kevinrob\\GuzzleCache\\": [ + "src/", + "tests/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kevin Robatel", + "email": "kevinrob2@gmail.com", + "homepage": "https://github.com/Kevinrob" + } + ], + "description": "A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)", + "homepage": "https://github.com/Kevinrob/guzzle-cache-middleware", + "keywords": [ + "Etag", + "Flysystem", + "Guzzle", + "cache", + "cache-control", + "doctrine", + "expiration", + "guzzle6", + "handler", + "http", + "http 1.1", + "middleware", + "performance", + "php", + "promise", + "psr6", + "psr7", + "rfc7234", + "validation" + ], + "time": "2016-06-17 08:34:36" + }, { "name": "kherge/version", "version": "1.0.1", @@ -2063,23 +2031,31 @@ "time": "2016-05-30 15:25:52" }, { - "name": "psr/log", - "version": "1.0.0", + "name": "psr/http-message", + "version": "1.0", "source": { "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", "shasum": "" }, + "require": { + "php": ">=5.3.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "psr-0": { - "Psr\\Log\\": "" + "psr-4": { + "Psr\\Http\\Message\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -2092,44 +2068,36 @@ "homepage": "http://www.php-fig.org/" } ], - "description": "Common interface for logging libraries", + "description": "Common interface for HTTP messages", "keywords": [ - "log", + "http", + "http-message", "psr", - "psr-3" + "psr-7", + "request", + "response" ], - "time": "2012-12-21 11:40:51" + "time": "2015-05-04 20:22:00" }, { - "name": "react/promise", - "version": "v2.4.1", + "name": "psr/log", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/reactphp/promise.git", - "reference": "8025426794f1944de806618671d4fa476dc7626f" + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/8025426794f1944de806618671d4fa476dc7626f", - "reference": "8025426794f1944de806618671d4fa476dc7626f", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", "shasum": "" }, - "require": { - "php": ">=5.4.0" - }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, "autoload": { - "psr-4": { - "React\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] + "psr-0": { + "Psr\\Log\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -2137,12 +2105,17 @@ ], "authors": [ { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "time": "2016-05-03 17:50:52" + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" }, { "name": "sebastian/comparator", diff --git a/src/LaunchDarkly/GuzzleFeatureRequester.php b/src/LaunchDarkly/GuzzleFeatureRequester.php index b8a144afe..a53385e67 100644 --- a/src/LaunchDarkly/GuzzleFeatureRequester.php +++ b/src/LaunchDarkly/GuzzleFeatureRequester.php @@ -2,36 +2,34 @@ namespace LaunchDarkly; use GuzzleHttp\Client; -use \GuzzleHttp\Exception\BadResponseException; -use \GuzzleHttp\Subscriber\Cache\CacheSubscriber; - -class GuzzleFeatureRequester implements FeatureRequester { +use GuzzleHttp\Exception\BadResponseException; +use GuzzleHttp\HandlerStack; +use Kevinrob\GuzzleCache\CacheMiddleware; +use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy; +class GuzzleFeatureRequester implements FeatureRequester +{ private $_client; - - function __construct($baseUri, $apiKey, $options) { - $this->_client = new Client(array( - 'base_url' => $baseUri, - 'defaults' => array( - 'headers' => array( - 'Authorization' => "api_key {$apiKey}", - 'Content-Type' => 'application/json', - 'User-Agent' => 'PHPClient/' . LDClient::VERSION - ), - 'debug' => false, - 'timeout' => $options['timeout'], - 'connect_timeout' => $options['connect_timeout'] - ) - )); - - if (!isset($options['cache_storage'])) { - $csOptions = array('validate' => false); - } - else { - $csOptions = array('storage' => $options['cache_storage'], 'validate' => false); - } - - CacheSubscriber::attach($this->_client, $csOptions); + private $_baseUri; + private $_defaults; + + function __construct($baseUri, $apiKey, $options) + { + $this->_baseUri = $baseUri; + error_log("uri: $baseUri"); + $stack = HandlerStack::create(); + $stack->push(new CacheMiddleware(new PublicCacheStrategy(isset($options['cache']) ? $options['cache'] : null), 'cache')); + + $this->_defaults = array( + 'headers' => array( + 'Authorization' => "api_key {$apiKey}", + 'Content-Type' => 'application/json', + 'User-Agent' => 'PHPClient/' . LDClient::VERSION + ), + 'timeout' => $options['timeout'], + 'connect_timeout' => $options['connect_timeout'] + ); + $this->_client = new Client(['handler' => $stack, 'debug' => false]); } @@ -41,10 +39,13 @@ function __construct($baseUri, $apiKey, $options) { * @param $key string feature key * @return array|null The decoded JSON feature data, or null if missing */ - public function get($key) { + public function get($key) + { try { - $response = $this->_client->get("/api/eval/features/$key"); - return $response->json(); + $uri = $this->_baseUri . "/api/eval/features/$key"; + $response = $this->_client->get($uri, $this->_defaults); + $body = $response->getBody(); + return json_decode($body, true); } catch (BadResponseException $e) { $code = $e->getResponse()->getStatusCode(); error_log("GuzzleFeatureRetriever::get received an unexpected HTTP status code $code"); diff --git a/src/LaunchDarkly/LDClient.php b/src/LaunchDarkly/LDClient.php index d93491361..6b38f25f6 100644 --- a/src/LaunchDarkly/LDClient.php +++ b/src/LaunchDarkly/LDClient.php @@ -8,7 +8,7 @@ */ class LDClient { const DEFAULT_BASE_URI = 'https://app.launchdarkly.com'; - const VERSION = '0.7.0'; + const VERSION = '1.0.0'; protected $_apiKey; protected $_baseUri; @@ -29,7 +29,7 @@ class LDClient { * - base_uri: Base URI of the LaunchDarkly API. Defaults to `DEFAULT_BASE_URI` * - timeout: Float describing the maximum length of a request in seconds. Defaults to 3 * - connect_timeout: Float describing the number of seconds to wait while trying to connect to a server. Defaults to 3 - * - cache_storage: An optional GuzzleHttp\Subscriber\Cache\CacheStorageInterface. Defaults to an in-memory cache. + * - cache: An optional Kevinrob\GuzzleCache\Strategy\CacheStorageInterface. Defaults to an in-memory cache. */ public function __construct($apiKey, $options = array()) { $this->_apiKey = $apiKey;