Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [2.0.2] - 2021-03-02
### Added
- Add Support for PHP 8
## [2.0.1] - 2018-12-16
### Fixed
- `\Http\Adapter\Guzzle6\Client::sendRequest` no longer throws any exceptions that do not implement
the PSR exception interface.
Instead of `\UnexpectedValueException` we now throw `Http\Adapter\Guzzle6\Exception\UnexpectedValueException`
(which extends `\UnexpectedValueException` and implements `Psr\Http\Client\ClientExceptionInterface`).
Instead of `\RuntimeException` we now throw `Http\Client\Exception\TransferException`
(which extends `\RuntimeException` and implements `Psr\Http\Client\ClientExceptionInterface`).
## [2.0.0] - 2018-11-14
### Added
- Support for HTTPlug 2.0 and PSR-18
### Changed
- `Client` and `Promise` are both final
### Removed
- Support for PHP <7.1
## [1.1.1] - 2016-05-10
### Fixed
- Adapter can again be instantiated without a guzzle client.
## [1.1.0] - 2016-05-09
### Added
- Factory method Client::createWithConfig to create an adapter with custom
configuration for the underlying guzzle client.
## [1.0.0] - 2016-01-26
## [0.4.1] - 2016-01-13
### Changed
- Updated integration tests
### Removed
- Client common dependency
## [0.4.0] - 2016-01-12
### Changed
- Updated package files
- Updated HTTPlug to RC1
## [0.3.1] - 2015-12-31
## [0.3.0] - 2015-12-31
## [0.2.1] - 2015-12-17
### Added
- Puli configuration and bindings
### Changed
- Guzzle setup conforms to HTTPlug requirement now: Minimal functionality in client
## [0.2.0] - 2015-12-15
### Added
- Async client capabalities
### Changed
- HTTPlug instead of HTTP Adapter
## 0.1.0 - 2015-06-12
### Added
- Initial release

20
vendor/php-http/guzzle6-adapter/LICENSE vendored Normal file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2014-2015 Eric GELOEN <geloen.eric@gmail.com>
Copyright (c) 2015-2016 PHP HTTP Team <team@php-http.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,62 @@
# Guzzle 6 HTTP Adapter
[![Latest Version](https://img.shields.io/github/release/php-http/guzzle6-adapter.svg?style=flat-square)](https://github.com/php-http/guzzle6-adapter/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/php-http/guzzle6-adapter.svg?style=flat-square)](https://travis-ci.org/php-http/guzzle6-adapter)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/guzzle6-adapter.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/guzzle6-adapter)
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/guzzle6-adapter.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/guzzle6-adapter)
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/guzzle6-adapter.svg?style=flat-square)](https://packagist.org/packages/php-http/guzzle6-adapter)
**Guzzle 6 HTTP Adapter.**
**Note for PHP 8**: This adapter can now be installed with PHP 8, even though Guzzle 6 is not tested on PHP 8.
If you need a PSR-18 client, use Guzzle 7 which natively implements PSR-18.
If you need the HTTPlug interfaces for asynchronous calls or for a system that still requires HTTPlug, use the [guzzle7-adapter](https://github.com/php-http/guzzle7-adapter/) instead of this repository.
## Install
Via Composer
``` bash
$ composer require php-http/guzzle6-adapter
```
## Documentation
Please see the [official documentation](http://docs.php-http.org/en/latest/clients/guzzle6-adapter.html).
## Testing
First launch the http server:
```bash
$ ./vendor/bin/http_test_server > /dev/null 2>&1 &
```
Then the test suite:
``` bash
$ composer test
```
## Contributing
Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).
## Security
If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org).
## Credits
Thanks to [David de Boer](https://github.com/ddeboer) for implementing this adapter.
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.

View File

@@ -0,0 +1,52 @@
{
"name": "php-http/guzzle6-adapter",
"description": "Guzzle 6 HTTP Adapter",
"license": "MIT",
"keywords": ["guzzle", "http"],
"homepage": "http://httplug.io",
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com"
}
],
"require": {
"php": "^7.1 || ^8.0",
"php-http/httplug": "^2.0",
"psr/http-client": "^1.0",
"guzzlehttp/guzzle": "^6.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^7.4 || ^8.4",
"php-http/client-integration-tests": "^2.0 || ^3.0"
},
"provide": {
"php-http/client-implementation": "1.0",
"php-http/async-client-implementation": "1.0",
"psr/http-client-implementation": "1.0"
},
"autoload": {
"psr-4": {
"Http\\Adapter\\Guzzle6\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Http\\Adapter\\Guzzle6\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
}
}

View File

@@ -0,0 +1,16 @@
{
"version": "1.0",
"name": "php-http/guzzle6-adapter",
"bindings": {
"04b5a002-71a8-473d-a8df-75671551b84a": {
"_class": "Puli\\Discovery\\Binding\\ClassBinding",
"class": "Http\\Adapter\\Guzzle6\\Client",
"type": "Http\\Client\\HttpClient"
},
"9c856476-7f6b-43df-a740-15420a5f839c": {
"_class": "Puli\\Discovery\\Binding\\ClassBinding",
"class": "Http\\Adapter\\Guzzle6\\Client",
"type": "Http\\Client\\HttpAsyncClient"
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Http\Adapter\Guzzle6;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* HTTP Adapter for Guzzle 6.
*
* @author David de Boer <david@ddeboer.nl>
*/
final class Client implements HttpClient, HttpAsyncClient
{
/**
* @var ClientInterface
*/
private $client;
/**
* If you pass a Guzzle instance as $client, make sure to configure Guzzle to not
* throw exceptions on HTTP error status codes, or this adapter will violate PSR-18.
* See also self::buildClient at the bottom of this class.
*/
public function __construct(?ClientInterface $client = null)
{
if (!$client) {
$client = self::buildClient();
}
$this->client = $client;
}
/**
* Factory method to create the Guzzle 6 adapter with custom Guzzle configuration.
*/
public static function createWithConfig(array $config): Client
{
return new self(self::buildClient($config));
}
/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
$promise = $this->sendAsyncRequest($request);
return $promise->wait();
}
/**
* {@inheritdoc}
*/
public function sendAsyncRequest(RequestInterface $request)
{
$promise = $this->client->sendAsync($request);
return new Promise($promise, $request);
}
/**
* Build the Guzzle client instance.
*/
private static function buildClient(array $config = []): GuzzleClient
{
$handlerStack = new HandlerStack(\GuzzleHttp\choose_handler());
$handlerStack->push(Middleware::prepareBody(), 'prepare_body');
$config = array_merge(['handler' => $handlerStack], $config);
return new GuzzleClient($config);
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Http\Adapter\Guzzle6\Exception;
use Http\Client\Exception;
final class UnexpectedValueException extends \UnexpectedValueException implements Exception
{
}

View File

@@ -0,0 +1,134 @@
<?php
declare(strict_types=1);
namespace Http\Adapter\Guzzle6;
use GuzzleHttp\Exception as GuzzleExceptions;
use GuzzleHttp\Promise\PromiseInterface;
use Http\Adapter\Guzzle6\Exception\UnexpectedValueException;
use Http\Client\Exception as HttplugException;
use Http\Promise\Promise as HttpPromise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Wrapper around Guzzle promises.
*
* @author Joel Wurtz <joel.wurtz@gmail.com>
*/
final class Promise implements HttpPromise
{
/**
* @var PromiseInterface
*/
private $promise;
/**
* @var string State of the promise
*/
private $state;
/**
* @var ResponseInterface
*/
private $response;
/**
* @var HttplugException
*/
private $exception;
/**
* @var RequestInterface
*/
private $request;
public function __construct(PromiseInterface $promise, RequestInterface $request)
{
$this->request = $request;
$this->state = self::PENDING;
$this->promise = $promise->then(function ($response) {
$this->response = $response;
$this->state = self::FULFILLED;
return $response;
}, function ($reason) use ($request) {
$this->state = self::REJECTED;
if ($reason instanceof HttplugException) {
$this->exception = $reason;
} elseif ($reason instanceof GuzzleExceptions\GuzzleException) {
$this->exception = $this->handleException($reason, $request);
} elseif ($reason instanceof \Throwable) {
$this->exception = new HttplugException\TransferException('Invalid exception returned from Guzzle6', 0, $reason);
} else {
$this->exception = new UnexpectedValueException('Reason returned from Guzzle6 must be an Exception');
}
throw $this->exception;
});
}
/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
return new static($this->promise->then($onFulfilled, $onRejected), $this->request);
}
/**
* {@inheritdoc}
*/
public function getState()
{
return $this->state;
}
/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
$this->promise->wait(false);
if ($unwrap) {
if (self::REJECTED == $this->getState()) {
throw $this->exception;
}
return $this->response;
}
}
/**
* Converts a Guzzle exception into an Httplug exception.
*/
private function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request): HttplugException
{
if ($exception instanceof GuzzleExceptions\SeekException) {
return new HttplugException\RequestException($exception->getMessage(), $request, $exception);
}
if ($exception instanceof GuzzleExceptions\ConnectException) {
return new HttplugException\NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
}
if ($exception instanceof GuzzleExceptions\RequestException) {
// Make sure we have a response for the HttpException
if ($exception->hasResponse()) {
return new HttplugException\HttpException(
$exception->getMessage(),
$exception->getRequest(),
$exception->getResponse(),
$exception
);
}
return new HttplugException\RequestException($exception->getMessage(), $exception->getRequest(), $exception);
}
return new HttplugException\TransferException($exception->getMessage(), 0, $exception);
}
}