diff --git a/CHANGELOG.md b/CHANGELOG.md index 1778c176fc83d27cca2d36a63d915cbb84dc86e7..1ff3064a81873076614888fa3d014313485a12ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.27.01 +* #61261 - nategood/httpful has been replaced by the guzzle http client + ## 2.27.0 * Compatibility with PHP80 established and set as minimum requirement for composer * Introduction of Opensearch as an additional search engine \ No newline at end of file diff --git a/bin/dldbget b/bin/dldbget index 2ca89bd418bd7a2658b6e270520315c96f754218..0f1eebc9183c7e4d931222264b4f42fd875f2ae9 100755 --- a/bin/dldbget +++ b/bin/dldbget @@ -9,7 +9,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $localInclude . PATH_SEPA require('autoload.php'); use Garden\Cli\Cli; -use \Httpful\Request; +use GuzzleHttp\Client; $cli = new Cli(); @@ -28,28 +28,32 @@ if (!is_writeable($destinationPath) || !is_dir($destinationPath)) { } $baseDomain = $args->getOpt("base"); -$client = Request::init() - ->withoutAutoParsing() - ->followRedirects() - ->timeout(30); -$proxy = $args->getOpt('proxy') ? $args->getOpt('proxy') : getenv('HTTP_PROXY'); +$clientOptions = [ + 'http_errors' => false, + 'timeout' => 30, + 'allow_redirects' => true, +]; +$proxy = $args->getOpt('proxy') ?: getenv('HTTP_PROXY'); if ($proxy) { - $proxyconf = array(); + $proxyconf = []; preg_match('#^(?:(?P<user>[^:]+):(?P<pass>[^@]+)@)?(?P<host>[^:]+):?(?P<port>\d+)?$#', $proxy, $proxyconf); - $proxyconf = array_merge(array('host' => '','port' => '80','user' => false,'pass' => false), $proxyconf); + $proxyconf = array_merge([ + 'host' => '', + 'port' => '80', + 'user' => false, + 'pass' => false + ], $proxyconf); + $proxyUrl = $proxyconf['host'] . ':' . $proxyconf['port']; + if ($proxyconf['user']) { - $client->useProxy( - $proxyconf['host'], - $proxyconf['port'], - CURLAUTH_BASIC, - $proxyconf['user'], - $proxyconf['pass'] - ); + $proxyUrl = $proxyconf['user'] . ':' . $proxyconf['pass'] . '@' . $proxyUrl; + $proxyUrl = 'http://' . $proxyUrl; } else { - $client->useProxy($proxyconf['host'], $proxyconf['port']); + $proxyUrl = 'http://' . $proxyUrl; } + $clientOptions['proxy'] = $proxyUrl; } -Request::ini($client); +$client = new Client($clientOptions); $downloads = array( array( @@ -92,23 +96,19 @@ foreach ($downloads as $download) { $oldContent = json_decode($oldContentJson, true); $oldContentJson = null; - $request = Request::get($baseDomain . $download['url']); - + $requestOptions = []; if (isset($oldContent['hash']) && !empty($oldContent['hash'])) { - $request->addHeader('If-None-Match', $oldContent['hash']); + $requestOptions['headers']['If-None-Match'] = $oldContent['hash']; } - $oldContent = null; - $response = $request - //->followRedirects() - ->send() - ; + $response = $client->get($baseDomain . $download['url'], $requestOptions); + $oldContent = null; - if (304 == $response->code) { + if ($response->getStatusCode() == 304) { continue; } - $json = $response->body; + $json = (string)$response->getBody(); $tmp = $destinationPath . DIRECTORY_SEPARATOR . 'tmp.' . $download['file']; file_put_contents($tmp, $json); $data = json_decode($json, true); diff --git a/bin/dldbget-v2 b/bin/dldbget-v2 index ff5919f608c38fe068465af81d6769d6ebb2dc11..ce678dd45bd4b5c41dd6e4567997d11a1bdd848c 100755 --- a/bin/dldbget-v2 +++ b/bin/dldbget-v2 @@ -9,7 +9,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $localInclude . PATH_SEPA require('autoload.php'); use Garden\Cli\Cli; -use \Httpful\Request; +use GuzzleHttp\Client; try { @@ -37,42 +37,44 @@ try { $baseDomain = $args->getOpt("base"); $auth = $args->getOpt("auth", ""); - $client = Request::init() - ->withoutAutoParsing() - ->followRedirects() - ->timeout(30); - + $clientOptions = [ + 'http_errors' => false, + 'timeout' => 30, + 'allow_redirects' => true, + ]; $proxy = $args->getOpt('proxy') ? $args->getOpt('proxy') : getenv('HTTP_PROXY'); if ($proxy) { - $proxyconf = array(); + $proxyconf = []; preg_match('#^(?:(?P<user>[^:]+):(?P<pass>[^@]+)@)?(?P<host>[^:]+):?(?P<port>\d+)?$#', $proxy, $proxyconf); - $proxyconf = array_merge(array('host' => '','port' => '80','user' => false,'pass' => false), $proxyconf); + $proxyconf = array_merge([ + 'host' => '', + 'port' => '80', + 'user' => false, + 'pass' => false + ], $proxyconf); + $proxyUrl = $proxyconf['host'] . ':' . $proxyconf['port']; + if ($proxyconf['user']) { - $client->useProxy( - $proxyconf['host'], - $proxyconf['port'], - CURLAUTH_BASIC, - $proxyconf['user'], - $proxyconf['pass'] - ); + $proxyUrl = $proxyconf['user'] . ':' . $proxyconf['pass'] . '@' . $proxyUrl; + $proxyUrl = 'http://' . $proxyUrl; } else { - $client->useProxy($proxyconf['host'], $proxyconf['port']); + $proxyUrl = 'http://' . $proxyUrl; } + $clientOptions['proxy'] = $proxyUrl; } - Request::ini($client); - - $request = Request::get($baseDomain . '/export/json/availablelanguages/'); + $client = new Client($clientOptions); + $requestOptions = []; $hasAuth = false; if (!empty($auth)) { $hasAuth = true; $auth = explode(':', $auth, 2); - $request->authenticateWith($auth[0], $auth[1]); - } - - $respronse = $request->send(); - $json = $respronse->body; + // Füge die Authentifizierungsdaten zu den Optionen hinzu + $requestOptions[RequestOptions::AUTH] = [$auth[0], $auth[1]]; + } + $response = $client->get($baseDomain . '/export/json/availablelanguages/', $requestOptions); + $json = json_decode($response->getBody(), true); $availablelanguages = json_decode($json, true); if (!array_key_exists('data', $availablelanguages) || 0 == count($availablelanguages['data'])) { @@ -142,25 +144,23 @@ try { } $oldContent = json_decode($oldContentJson, true); - $request = Request::get($baseDomain . $download['url']); - + $requestOptions = []; if (isset($oldContent['hash']) && !empty($oldContent['hash'])) { - $request->addHeader('If-None-Match', $oldContent['hash']); + $requestOptions[RequestOptions::HEADERS] = [ + 'If-None-Match' => $oldContent['hash'] + ]; } - if (true === $hasAuth) { - $request->authenticateWith($auth[0], $auth[1]); + if ($hasAuth === true) { + $auth = explode(':', $auth, 2); + $requestOptions[RequestOptions::AUTH] = [$auth[0], $auth[1]]; } + $response = $client->get($baseDomain . $download['url'], $requestOptions); - $respronse = $request - //->followRedirects() - ->send() - ; - - if (304 == $respronse->code) { + if ($response->getStatusCode() === 304) { continue; } - $json = $respronse->body; + $json = (string) $response->getBody(); $tmp = $destinationPath . DIRECTORY_SEPARATOR . 'tmp.' . $download['file']; file_put_contents($tmp, $json); $data = json_decode($json, true); diff --git a/composer.json b/composer.json index 634bf4efd1c59a4ca5ffa45bb874c1af39bc62d1..6af4e0e7ea37eb5c57dfbc8783304ace46316acb 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "ext-json": ">=1.0", "ext-pcre": ">=0", "vanilla/garden-cli": "1.*", - "nategood/httpful": "0.*", + "guzzlehttp/guzzle": "^7.9.2", "twig/twig": "3.*" }, "bin": ["bin/dldbget"], diff --git a/composer.lock b/composer.lock index d365d82135d21728d1952cb3e2086dc2a9eeb88f..54e5876d9db277a39c8facdeb3c0a200cf9da01a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,33 +4,59 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8eb834b35b80abfca7d18dfde3df176d", + "content-hash": "f634aa1c47d5d465023fd6014d102a60", "packages": [ { - "name": "nategood/httpful", - "version": "0.3.2", + "name": "guzzlehttp/guzzle", + "version": "7.9.2", "source": { "type": "git", - "url": "https://github.com/nategood/httpful.git", - "reference": "0cded3ea97ba905600de9ceb9ef13f3ab681587c" + "url": "https://github.com/guzzle/guzzle.git", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nategood/httpful/zipball/0cded3ea97ba905600de9ceb9ef13f3ab681587c", - "reference": "0cded3ea97ba905600de9ceb9ef13f3ab681587c", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b", "shasum": "" }, "require": { - "ext-curl": "*", - "php": ">=7.2" + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.3", + "guzzlehttp/psr7": "^2.7.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "*" + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "guzzle/client-integration-tests": "3.0.2", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" }, "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, "autoload": { - "psr-0": { - "Httpful": "src/" + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -39,26 +65,475 @@ ], "authors": [ { - "name": "Nate Good", - "email": "me@nategood.com", - "homepage": "http://nategood.com" + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], - "description": "A Readable, Chainable, REST friendly, PHP HTTP Client", - "homepage": "http://github.com/nategood/httpful", + "description": "Guzzle is a PHP HTTP client library", "keywords": [ - "api", + "client", "curl", + "framework", "http", - "requests", + "http client", + "psr-18", + "psr-7", "rest", - "restful" + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.9.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2024-07-24T11:22:20+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2024-07-18T10:29:17+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.7.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2024-07-18T11:15:46+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } ], + "description": "A polyfill for getallheaders.", "support": { - "issues": "https://github.com/nategood/httpful/issues", - "source": "https://github.com/nategood/httpful/tree/v0.3.2" + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" }, - "time": "2020-01-25T01:13:13+00:00" + "time": "2019-03-08T08:55:37+00:00" }, { "name": "symfony/deprecation-contracts",