diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5c47f76 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/appveyor.yml export-ignore +/CHANGELOG.md export-ignore +/phpcs.xml.dist export-ignore +/phpunit.xml.dist export-ignore +/README.md export-ignore +/tests export-ignore diff --git a/.travis.yml b/.travis.yml index 5f97515..38b521b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,15 +14,6 @@ matrix: php: '7.3' env: require=1 dependencies=highest - - name: '[CS] PHP 7.2 With Locked Dependencies' - php: '7.2' - env: cs=1 - - name: '[CS] PHP 7.2 With Lowest Dependencies' - php: '7.2' - env: cs=1 dependencies=lowest - - name: '[CS] PHP 7.2 With Highest Dependencies' - php: '7.2' - env: cs=1 dependencies=highest - name: '[CS] PHP 7.3 With Locked Dependencies' php: '7.3' env: cs=1 @@ -38,34 +29,28 @@ matrix: - name: '[CS] PHP Nightly With Lowest Dependencies' php: nightly env: cs=1 dependencies=lowest - - name: '[CS] PHP Nightly With HIghest Dependencies' + - name: '[CS] PHP Nightly With Highest Dependencies' php: nightly env: cs=1 dependencies=highest - - name: '[UNIT] PHP 7.2 With Locked Dependencies' - php: '7.2' - - name: '[UNIT] PHP 7.2 With Lowest Dependencies' - php: '7.2' - env: dependencies=lowest - - name: '[UNIT] PHP 7.2 With Highest Dependencies' - php: '7.2' - env: dependencies=highest - name: '[UNIT] PHP 7.3 With Locked Dependencies' php: '7.3' + env: unit=1 - name: '[UNIT] PHP 7.3 With Lowest Dependencies' php: '7.3' - env: dependencies=lowest + env: dependencies=lowest unit=1 - name: '[UNIT] PHP 7.3 With Highest Dependencies' php: '7.3' - env: dependencies=highest + env: dependencies=highest unit=1 - name: '[UNIT] PHP Nightly With Locked Dependencies' php: nightly + env: unit=1 - name: '[UNIT] PHP Nightly With Highest Dependencies' php: nightly - env: dependencies=lowest + env: dependencies=highest unit=1 - name: '[UNIT] PHP Nightly With Lowest Dependencies' php: nightly - env: dependencies=highest + env: dependencies=lowest unit=1 allow_failures: - name: '[CS] PHP Nightly With Locked Dependencies' php: nightly @@ -73,36 +58,41 @@ matrix: - name: '[CS] PHP Nightly With Lowest Dependencies' php: nightly env: cs=1 dependencies=lowest - - name: '[CS] PHP Nightly With HIghest Dependencies' + - name: '[CS] PHP Nightly With Highest Dependencies' php: nightly env: cs=1 dependencies=highest - name: '[UNIT] PHP Nightly With Locked Dependencies' php: nightly + env: unit=1 - name: '[UNIT] PHP Nightly With Highest Dependencies' php: nightly - env: dependencies=lowest + env: dependencies=highest unit=1 - name: '[UNIT] PHP Nightly With Lowest Dependencies' php: nightly - env: dependencies=highest + env: dependencies=lowest unit=1 + +services: + - redis-server before_install: -- phpenv config-rm xdebug.ini || echo "No xdebug config." -- composer self-update + - phpenv config-rm xdebug.ini || echo "No xdebug config." + - composer self-update install: -- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar -- chmod +x php-coveralls.phar + - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar + - chmod +x php-coveralls.phar before_script: - - if [ -z "$dependencies" ]; then travis_retry composer install --no-scripts; fi; - - if [ "$dependencies" = "lowest" ]; then travis_retry composer update --no-scripts --prefer-lowest -n; fi; - - if [ "$dependencies" = "highest" ]; then travis_retry composer update --no-scripts -n; fi; + - if [ -z "$dependencies" ]; then travis_retry composer install -n; fi; + - if [ "$dependencies" = "lowest" ]; then travis_retry composer update --prefer-lowest -n; fi; + - if [ "$dependencies" = "highest" ]; then travis_retry composer update -n; fi; script: - - if [ -z "$cs" ] && [ -z "$require" ]; then phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml; fi; + - if [ "$unit" = 1 ]; then phpdbg -qrr vendor/bin/phpunit --testsuite HarmonIOHttpClientUnitTestSuite --coverage-text --coverage-clover build/logs/clover.xml; fi; + - if [ "$integration" = 1 ]; then phpdbg -qrr vendor/bin/phpunit --testsuite HarmonIOHttpClientIntegrationTestSuite --coverage-text --coverage-clover build/logs/clover.xml; fi; - if [ "$cs" = 1 ]; then vendor/bin/phpcs -s; fi; - if [ "$require" = 1 ]; then vendor/bin/composer-require-checker check; fi; after_success: - - if [ -z "$cs" ] && [ -z "$require" ]; then travis_retry php php-coveralls.phar; fi; + - if [ "$unit" = 1 ]; then travis_retry php php-coveralls.phar; fi; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..db91510 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] - 0000-00-00 + +### Added + +*None* + +### Changed + +*None* + +### Deprecated + +*None* + +### Removed + +*None* + +### Fixed + +*None* + +### Security + +*None* diff --git a/README.md b/README.md index d8213ca..e431730 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,137 @@ [![Build status](https://ci.appveyor.com/api/projects/status/qe3volxj5pxqaguu/branch/master?svg=true)](https://ci.appveyor.com/project/PeeHaa/http-client/branch/master) [![Coverage Status](https://coveralls.io/repos/github/HarmonyIO/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/HarmonyIO/Http-Client?branch=master) [![License](https://poser.pugx.org/harmonyio/http-client/license)](https://packagist.org/packages/harmonyio/http-client) + +Async caching aware http client + +## Requirements + +- PHP 7.3 +- Redis (if wanting to use the Redis caching provider) + +In addition for non-blocking context one of the following event libraries should be installed: + +- [ev](https://pecl.php.net/package/ev) +- [event](https://pecl.php.net/package/event) +- [php-uv](https://github.com/bwoebi/php-uv) + +## Installation + +``` +composer require harmonyio/http-client +``` + +## Usage + +### Caching requests + +The following example shows how to make a request and cache the result so consecutive calls will used the cached results instead of making a new external HTTP call. + +```php +request($request)); + +// all consecutive requests will now used the cached result instead of calling the external service again +$result = wait($httpClient->request($request)); +``` + +### Non-caching requests + +It is also possible to make non-caching requests. + +```php +request($request)); + +// make the same request again +$result = wait($httpClient->request($request)); +``` + +## Client interface + +The HTTP client's interface only contains a single method: `Client::request(\HarmonyIO\HttpClient\Message\Request $request)`. + +The `$request` parameter can be either a "normal" non-caching request (`HarmonyIO\HttpClient\Message\Request`) or a caching request (`HarmonyIO\HttpClient\Message\CachingRequest`). + +### `HarmonyIO\HttpClient\Message\Request` + +The constructor of the request class expects at least a URL to make the request to and optionally an HTTP method (defaults to GET). + +Optional request parts can be set in setter method of the request class: + +```php +setProtocolVersions('1.1', '2.0') + ->addHeader('foo', 'bar') + ->addHeader('baz', 'qux') + ->setBody('foobar') +; +``` + +### `HarmonyIO\HttpClient\Message\CachingRequest` + +The constructor of the caching request class expects at least a key, a TTL, the URL to make the request to and optionally an HTTP method (defaults to GET). + +Optional request parts can be set in setter method of the request class as defined in the previous section. + +```php +setProtocolVersions('1.1', '2.0') + ->addHeader('foo', 'bar') + ->addHeader('baz', 'qux') +; +``` diff --git a/appveyor.yml b/appveyor.yml index 988b253..cc0d349 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,55 +1,72 @@ build: false - +clone_folder: c:\projects\http_client +clone_depth: 1 platform: - x64 - -clone_folder: c:\projects\php-project-workspace - -## Build matrix for lowest and highest possible targets environment: matrix: - - dependencies: current - php_ver_target: 7.2 - - dependencies: lowest - php_ver_target: 7.2 - - dependencies: highest - php_ver_target: 7.2 + - dependencies: current + php_ver_target: 7.3 + - dependencies: lowest + php_ver_target: 7.3 + - dependencies: highest + php_ver_target: 7.3 -## Cache composer, chocolatey and php bits + project_directory: c:\projects\http_client + composer_directory: c:\tools\composer + composer_executable: c:\tools\composer\composer.phar + composer_installer: c:\tools\composer\installer.php + php_directory: c:\tools\php cache: - - '%LOCALAPPDATA%\Composer\files -> composer.lock' - - composer.phar - - C:\ProgramData\chocolatey\bin -> .appveyor.yml - - C:\ProgramData\chocolatey\lib -> .appveyor.yml - - c:\tools\php -> .appveyor.yml - -## Set up environment varriables + - c:\ProgramData\chocolatey\bin -> appveyor.yml + - c:\ProgramData\chocolatey\lib -> appveyor.yml + - c:\tools\composer -> appveyor.yml + - '%LOCALAPPDATA%\Composer -> appveyor.yml' + - c:\tools\php -> appveyor.yml init: - - SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH% - - SET COMPOSER_NO_INTERACTION=1 - - SET PHP=1 - - SET ANSICON=121x90 (121x90) - -## Install PHP and composer, and run the appropriate composer command + - ps: $Env:PATH = $Env:php_directory + ';' + $Env:composer_directory + ';' + $Env:PATH + - SET PATH=C:\Program Files\OpenSSL;%PATH% + - SET COMPOSER_NO_INTERACTION=1 + - SET PHP=1 + - SET ANSICON=121x90 (121x90) install: - - IF EXIST c:\tools\php (SET PHP=0) - - ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','') - - cd c:\tools\php - - IF %PHP%==1 copy php.ini-production php.ini /Y - - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - - IF %PHP%==1 echo extension_dir=ext >> php.ini - - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini - - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini - - IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini - - IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat - - appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar - - cd c:\projects\php-project-workspace - - IF %dependencies%==lowest appveyor-retry composer update --no-scripts --prefer-lowest --no-progress --profile -n - - IF %dependencies%==current appveyor-retry composer install --no-scripts --no-progress --profile - - IF %dependencies%==highest appveyor-retry composer update --no-scripts --no-progress --profile -n - - composer show + # Install Redis + - nuget install redis-64 -excludeversion + - redis-64\tools\redis-server.exe --service-install + - redis-64\tools\redis-server.exe --service-start + + # Install PHP + - ps: If ((Test-Path $Env:php_directory) -eq $False) { New-Item -Path $Env:php_directory -ItemType 'directory' } + - ps: $php_install_parameters = '"/DontAddToPath /InstallDir:' + $Env:php_directory + '"' + - ps: appveyor-retry choco upgrade php --yes --version=$Env:exact_php_version --params=$php_install_parameters + + # Prepare PHP + - ps: cd $Env:php_directory + - ps: Copy-Item php.ini-production -Destination php.ini + - ps: Add-Content -Path php.ini -Value 'memory_limit=1G' + - ps: Add-Content -Path php.ini -Value 'date.timezone="UTC"' + - ps: Add-Content -Path php.ini -Value 'extension_dir=ext' + - ps: Add-Content -Path php.ini -Value 'extension=php_curl.dll' + - ps: Add-Content -Path php.ini -Value 'extension=php_mbstring.dll' + - ps: Add-Content -Path php.ini -Value 'extension=php_openssl.dll' + - ps: Add-Content -Path php.ini -Value 'extension=php_intl.dll' + - ps: Add-Content -Path php.ini -Value 'extension=php_fileinfo.dll' + - ps: Add-Content -Path php.ini -Value 'extension=php_gd2.dll' + - ps: php --version + + # Prepare composer + - ps: If ((Test-Path $Env:composer_directory) -eq $False) { New-Item -Path $Env:composer_directory -ItemType 'directory' } + - ps: If ((Test-Path $Env:composer_installer) -eq $False) { appveyor-retry appveyor DownloadFile https://getcomposer.org/installer -FileName $Env:composer_installer } + - ps: If ((Test-Path $Env:composer_executable) -eq $False) { php $Env:composer_installer --install-dir=$Env:composer_directory } + - ps: Set-Content -Path ($Env:composer_directory + '\composer.bat') -Value ('@php ' + $Env:composer_executable + ' %*') + + # Install dependencies + - ps: cd $Env:project_directory + - IF %dependencies%==current composer install --no-progress -n + - IF %dependencies%==lowest composer update --prefer-lowest --no-progress -n + - IF %dependencies%==highest composer update --prefer-dist --no-progress -n ## Run the actual test test_script: - - cd c:\projects\php-project-workspace - - phpdbg -qrr vendor/phpunit/phpunit/phpunit --coverage-text + - ps: cd $Env:project_directory + - phpdbg -qrr vendor/phpunit/phpunit/phpunit --coverage-text diff --git a/composer.json b/composer.json index 3a9af72..f837d68 100644 --- a/composer.json +++ b/composer.json @@ -12,19 +12,19 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.2", + "php": "^7.3", "ext-json": "*", - "amphp/amp": "^2.0", - "amphp/artax": "^3.0", - "harmonyio/cache": "dev-master" + "amphp/amp": "^2.1.1", + "amphp/artax": "^3.0.14", + "harmonyio/cache": "^1.0.0-rc1" }, "require-dev": { - "harmonyio/php-codesniffer-ruleset": "dev-master", - "harmonyio/phpunit-extension": "^0.1", - "maglnet/composer-require-checker": "^1.1", - "phpunit/phpunit": "^7.4", - "slevomat/coding-standard": "^4.8", - "squizlabs/php_codesniffer": "^3.3.1" + "harmonyio/php-codesniffer-ruleset": "^1.0.0-rc1", + "harmonyio/phpunit-extension": "^1.0.0-rc1", + "maglnet/composer-require-checker": "^1.1.0", + "phpunit/phpunit": "^7.5.1", + "slevomat/coding-standard": "^4.8.6", + "squizlabs/php_codesniffer": "^3.4.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 4f9bab4..d84dfe6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1f395b435a2b3dc3b03433b70296bf09", + "content-hash": "0cc769953988b658426f276aaa92253b", "packages": [ { "name": "amphp/amp", @@ -144,16 +144,16 @@ }, { "name": "amphp/byte-stream", - "version": "v1.5.0", + "version": "v1.5.1", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", - "reference": "37b9ab16bb8f69c825c3c4e553fe00da73dd6926" + "reference": "6bbfcb6f47e92577e739586ba0c87e867be70a23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/byte-stream/zipball/37b9ab16bb8f69c825c3c4e553fe00da73dd6926", - "reference": "37b9ab16bb8f69c825c3c4e553fe00da73dd6926", + "url": "https://api.github.com/repos/amphp/byte-stream/zipball/6bbfcb6f47e92577e739586ba0c87e867be70a23", + "reference": "6bbfcb6f47e92577e739586ba0c87e867be70a23", "shasum": "" }, "require": { @@ -199,7 +199,7 @@ "non-blocking", "stream" ], - "time": "2018-10-22T19:37:37+00:00" + "time": "2018-12-27T18:08:06+00:00" }, { "name": "amphp/cache", @@ -862,30 +862,32 @@ }, { "name": "harmonyio/cache", - "version": "dev-master", + "version": "v1.0.0-rc1", "source": { "type": "git", "url": "https://github.com/HarmonyIO/Cache.git", - "reference": "c7a1b1d99f917eac8a35c7556045bb520be92908" + "reference": "61ded07e411d7911cc826f3ee756fcb9509b2455" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/HarmonyIO/Cache/zipball/c7a1b1d99f917eac8a35c7556045bb520be92908", - "reference": "c7a1b1d99f917eac8a35c7556045bb520be92908", + "url": "https://api.github.com/repos/HarmonyIO/Cache/zipball/61ded07e411d7911cc826f3ee756fcb9509b2455", + "reference": "61ded07e411d7911cc826f3ee756fcb9509b2455", "shasum": "" }, "require": { - "amphp/amp": "^2.0", + "amphp/amp": "^2.1.1", + "amphp/cache": "^1.2", "amphp/redis": "^0.3.3", - "php": "^7.2" + "amphp/uri": "^0.1.3", + "php": "^7.3" }, "require-dev": { - "harmonyio/php-codesniffer-ruleset": "dev-master", - "harmonyio/phpunit-extension": "^0.1", - "maglnet/composer-require-checker": "^1.1", - "phpunit/phpunit": "^7.4", - "slevomat/coding-standard": "^4.8", - "squizlabs/php_codesniffer": "^3.3.1" + "harmonyio/php-codesniffer-ruleset": "^1.0.0-rc1", + "harmonyio/phpunit-extension": "^1.0.0-rc1", + "maglnet/composer-require-checker": "^1.1.0", + "phpunit/phpunit": "^7.5.1", + "slevomat/coding-standard": "^4.8.6", + "squizlabs/php_codesniffer": "^3.4.0" }, "type": "library", "autoload": { @@ -904,7 +906,7 @@ } ], "description": "Asynchronous caching library", - "time": "2018-12-03T09:49:30+00:00" + "time": "2018-12-28T00:41:06+00:00" }, { "name": "kelunik/certificate", @@ -1013,21 +1015,21 @@ }, { "name": "harmonyio/php-codesniffer-ruleset", - "version": "dev-master", + "version": "v1.0.0-rc1", "source": { "type": "git", "url": "https://github.com/HarmonyIO/PHP-CodeSniffer-Ruleset.git", - "reference": "d3678daabd50b81e88cacda3053f1e22f61a0f1b" + "reference": "ae732ba33cd99d58440d206ca90bbd080809c3a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/HarmonyIO/PHP-CodeSniffer-Ruleset/zipball/d3678daabd50b81e88cacda3053f1e22f61a0f1b", - "reference": "d3678daabd50b81e88cacda3053f1e22f61a0f1b", + "url": "https://api.github.com/repos/HarmonyIO/PHP-CodeSniffer-Ruleset/zipball/ae732ba33cd99d58440d206ca90bbd080809c3a8", + "reference": "ae732ba33cd99d58440d206ca90bbd080809c3a8", "shasum": "" }, "require": { - "slevomat/coding-standard": "^4.8", - "squizlabs/php_codesniffer": "^3.3" + "slevomat/coding-standard": "^4.8.6", + "squizlabs/php_codesniffer": "^3.4.0" }, "type": "library", "notification-url": "https://packagist.org/downloads/", @@ -1040,33 +1042,33 @@ "email": "info@pieterhordijk.com" } ], - "description": "HarmonyIO coding standard", - "time": "2018-11-19T19:25:34+00:00" + "description": "HarmonyIO coding standards", + "time": "2018-12-24T16:03:36+00:00" }, { "name": "harmonyio/phpunit-extension", - "version": "v0.1.0", + "version": "v1.0.0-rc1", "source": { "type": "git", "url": "https://github.com/HarmonyIO/PHPUnit-Extension.git", - "reference": "9292b4ae3a100a50b85262fa5c77f2824117fbe5" + "reference": "9654c0b2ddd9fb86f00fce77d35d42eabe84d266" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/HarmonyIO/PHPUnit-Extension/zipball/9292b4ae3a100a50b85262fa5c77f2824117fbe5", - "reference": "9292b4ae3a100a50b85262fa5c77f2824117fbe5", + "url": "https://api.github.com/repos/HarmonyIO/PHPUnit-Extension/zipball/9654c0b2ddd9fb86f00fce77d35d42eabe84d266", + "reference": "9654c0b2ddd9fb86f00fce77d35d42eabe84d266", "shasum": "" }, "require": { - "amphp/amp": "^2.0", - "php": "^7.2" + "amphp/amp": "^2.1.1", + "php": "^7.3", + "phpunit/phpunit": "^7.5.1" }, "require-dev": { - "harmonyio/php-codesniffer-ruleset": "dev-master", - "phpstan/phpstan": "^0.10.5", - "phpunit/phpunit": "^7.4", - "slevomat/coding-standard": "^4.8", - "squizlabs/php_codesniffer": "^3.3" + "harmonyio/php-codesniffer-ruleset": "1.0.0-rc1", + "maglnet/composer-require-checker": "^1.1.0", + "slevomat/coding-standard": "^4.8.6", + "squizlabs/php_codesniffer": "^3.4.0" }, "type": "library", "autoload": { @@ -1085,7 +1087,7 @@ } ], "description": "Asynchronous helpers for PHPUnit", - "time": "2018-11-07T02:17:55+00:00" + "time": "2018-12-24T18:07:04+00:00" }, { "name": "maglnet/composer-require-checker", @@ -1206,16 +1208,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.1.0", + "version": "v4.1.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "d0230c5c77a7e3cfa69446febf340978540958c0" + "reference": "8aae5b59b83bb4d0dbf07b0a835f2680a658f610" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/d0230c5c77a7e3cfa69446febf340978540958c0", - "reference": "d0230c5c77a7e3cfa69446febf340978540958c0", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8aae5b59b83bb4d0dbf07b0a835f2680a658f610", + "reference": "8aae5b59b83bb4d0dbf07b0a835f2680a658f610", "shasum": "" }, "require": { @@ -1253,7 +1255,7 @@ "parser", "php" ], - "time": "2018-10-10T09:24:14+00:00" + "time": "2018-12-26T11:32:39+00:00" }, { "name": "phar-io/manifest", @@ -2563,20 +2565,21 @@ }, { "name": "symfony/console", - "version": "v4.1.7", + "version": "v4.2.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "432122af37d8cd52fba1b294b11976e0d20df595" + "reference": "4dff24e5d01e713818805c1862d2e3f901ee7dd0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/432122af37d8cd52fba1b294b11976e0d20df595", - "reference": "432122af37d8cd52fba1b294b11976e0d20df595", + "url": "https://api.github.com/repos/symfony/console/zipball/4dff24e5d01e713818805c1862d2e3f901ee7dd0", + "reference": "4dff24e5d01e713818805c1862d2e3f901ee7dd0", "shasum": "" }, "require": { "php": "^7.1.3", + "symfony/contracts": "^1.0", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -2600,7 +2603,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2627,7 +2630,133 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-10-31T09:30:44+00:00" + "time": "2018-11-27T07:40:44+00:00" + }, + { + "name": "symfony/contracts", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/contracts.git", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-12-05T08:06:11+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -2730,20 +2859,21 @@ }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "phpunit/phpunit": "^4.6", @@ -2776,7 +2906,7 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2018-12-25T11:19:39+00:00" }, { "name": "webmozart/glob", @@ -2874,14 +3004,11 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "harmonyio/cache": 20, - "harmonyio/php-codesniffer-ruleset": 20 - }, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.2", + "php": "^7.3", "ext-json": "*" }, "platform-dev": [] diff --git a/src/Message/CachingRequest.php b/src/Message/CachingRequest.php index d7e37a3..d904864 100644 --- a/src/Message/CachingRequest.php +++ b/src/Message/CachingRequest.php @@ -4,6 +4,7 @@ use HarmonyIO\Cache\CacheableRequest; use HarmonyIO\Cache\Key; +use HarmonyIO\Cache\Ttl; class CachingRequest extends Request implements CacheableRequest { @@ -12,10 +13,10 @@ class CachingRequest extends Request implements CacheableRequest /** @var string */ private $key; - /** @var int */ + /** @var Ttl */ private $ttl; - public function __construct(string $key, int $ttl, string $uri, string $method = 'GET') + public function __construct(string $key, Ttl $ttl, string $uri, string $method = 'GET') { $this->key = $key; $this->ttl = $ttl; @@ -28,7 +29,7 @@ public function getCachingKey(): Key return new Key(self::CACHE_TYPE, $this->key, md5(serialize($this))); } - public function getTtl(): int + public function getTtl(): Ttl { return $this->ttl; } diff --git a/src/Message/Request.php b/src/Message/Request.php index 5d2f0c7..2d722f5 100644 --- a/src/Message/Request.php +++ b/src/Message/Request.php @@ -32,6 +32,7 @@ public function addHeader(string $key, string $value): Request /** * @param string|RequestBody $body + * @throws InvalidBody */ public function setBody($body): Request { diff --git a/src/Message/Response.php b/src/Message/Response.php index 9a6bbe4..16ff915 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -93,7 +93,7 @@ public function serialize(): string * @param string $serialized * @throws InvalidCachedResponse */ - //phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint + // phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint public function unserialize($serialized): void { $cachedData = json_decode($serialized, true); diff --git a/tests/Unit/Client/ArtaxClientTest.php b/tests/Unit/Client/ArtaxClientTest.php index 4fc67e1..4a31b1a 100644 --- a/tests/Unit/Client/ArtaxClientTest.php +++ b/tests/Unit/Client/ArtaxClientTest.php @@ -10,6 +10,7 @@ use Amp\Loop; use Amp\Success; use HarmonyIO\Cache\Cache; +use HarmonyIO\Cache\Ttl; use HarmonyIO\HttpClient\Client\ArtaxClient; use HarmonyIO\HttpClient\Client\Client; use HarmonyIO\HttpClient\Message\CachingRequest; @@ -26,7 +27,7 @@ class ArtaxClientTest extends TestCase /** @var MockObject|Cache */ private $cache; - //phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint + // phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint public function setUp() { $this->artaxBaseClient = $this->createMock(ArtaxBaseClient::class); @@ -133,7 +134,7 @@ public function testRequestCachesCachingRequest(): void $artaxClient = new ArtaxClient($this->artaxBaseClient, $this->cache); Loop::run(static function () use ($artaxClient) { - yield $artaxClient->request(new CachingRequest('Key', 10, 'https://example.com')); + yield $artaxClient->request(new CachingRequest('Key', new Ttl(10), 'https://example.com')); }); } @@ -190,8 +191,8 @@ public function testRequestDoesNotCacheErroringCachingRequest(): void $artaxClient = new ArtaxClient($this->artaxBaseClient, $this->cache); Loop::run(static function () use ($artaxClient) { - yield $artaxClient->request(new CachingRequest('Key', 10, 'https://example.com')); - yield $artaxClient->request(new CachingRequest('Key', 10, 'https://example.com')); + yield $artaxClient->request(new CachingRequest('Key', new Ttl(10), 'https://example.com')); + yield $artaxClient->request(new CachingRequest('Key', new Ttl(10), 'https://example.com')); }); } @@ -248,8 +249,8 @@ public function testRequestUsesCacheForConsecutiveCachingRequests(): void $artaxClient = new ArtaxClient($this->artaxBaseClient, $this->cache); Loop::run(static function () use ($artaxClient) { - yield $artaxClient->request(new CachingRequest('Key', 10, 'https://example.com')); - yield $artaxClient->request(new CachingRequest('Key', 10, 'https://example.com')); + yield $artaxClient->request(new CachingRequest('Key', new Ttl(10), 'https://example.com')); + yield $artaxClient->request(new CachingRequest('Key', new Ttl(10), 'https://example.com')); }); } } diff --git a/tests/Unit/Message/CachingRequestTest.php b/tests/Unit/Message/CachingRequestTest.php index 1de2ba9..87e3d63 100644 --- a/tests/Unit/Message/CachingRequestTest.php +++ b/tests/Unit/Message/CachingRequestTest.php @@ -4,6 +4,7 @@ use HarmonyIO\Cache\CacheableRequest; use HarmonyIO\Cache\Key; +use HarmonyIO\Cache\Ttl; use HarmonyIO\HttpClient\Message\CachingRequest; use HarmonyIO\PHPUnitExtension\TestCase; @@ -13,19 +14,22 @@ public function testImplementsCachingInterface(): void { $this->assertInstanceOf( CacheableRequest::class, - (new CachingRequest('TestKey', 10, 'https://example.com')) + (new CachingRequest('TestKey', new Ttl(10), 'https://example.com')) ); } public function testGetCachingKey(): void { - $key = (new CachingRequest('TestKey', 10, 'https://example.com'))->getCachingKey(); + $key = (new CachingRequest('TestKey', new Ttl(10), 'https://example.com'))->getCachingKey(); $this->assertInstanceOf(Key::class, $key); } public function testGetTtl(): void { - $this->assertSame(10, (new CachingRequest('TestKey', 10, 'https://example.com'))->getTtl()); + $this->assertSame( + 10, + (new CachingRequest('TestKey', new Ttl(10), 'https://example.com'))->getTtl()->getTtlInSeconds() + ); } }