初始化仓库
This commit is contained in:
26
vendor/guzzlehttp/command/.php-cs-fixer.dist.php
vendored
Normal file
26
vendor/guzzlehttp/command/.php-cs-fixer.dist.php
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
$config = (new PhpCsFixer\Config())
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'@PHP71Migration:risky' => true,
|
||||
'@PHPUnit75Migration:risky' => true,
|
||||
'@Symfony' => true,
|
||||
'declare_strict_types' => false,
|
||||
'global_namespace_import' => false,
|
||||
'phpdoc_annotation_without_dot' => false,
|
||||
'phpdoc_summary' => false,
|
||||
'phpdoc_to_comment' => false,
|
||||
'single_line_throw' => false,
|
||||
'void_return' => false,
|
||||
'yoda_style' => false,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in(__DIR__.'/src')
|
||||
->in(__DIR__.'/tests')
|
||||
->name('*.php')
|
||||
)
|
||||
;
|
||||
|
||||
return $config;
|
||||
60
vendor/guzzlehttp/command/CHANGELOG.md
vendored
Normal file
60
vendor/guzzlehttp/command/CHANGELOG.md
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.0.0 - 2016-11-24
|
||||
|
||||
* Add badges to README.md
|
||||
* Switch README from .rst to .md format
|
||||
* Update dependencies
|
||||
* Add command to handler call to provide support for GuzzleServices
|
||||
|
||||
## 0.9.0 - 2016-01-30
|
||||
|
||||
* Updated to use Guzzle 6 and PSR-7.
|
||||
* Event system has been replaced with a middleware system
|
||||
* Middleware at the command layer work the same as middleware from the
|
||||
HTTP layer, but work with `Command` and `Result` objects instead of
|
||||
`Request` and `Response` objects
|
||||
* The command middleware is in a separate `HandlerStack` instance than the
|
||||
HTTP middleware.
|
||||
* `Result` objects are the result of executing a `Command` and are used to hold
|
||||
the parsed response data.
|
||||
* Asynchronous code now uses the `guzzlehttp/promises` package instead of
|
||||
`guzzlehttp/ringphp`, which means that asynchronous results are implemented
|
||||
as Promises/A+ compliant `Promise` objects, instead of futures.
|
||||
* The existing `Subscriber`s were removed.
|
||||
* The `ServiceClientInterface` and `ServiceClient` class now provide the basic
|
||||
foundation of a web service client.
|
||||
|
||||
## 0.8.0 - 2015-02-02
|
||||
|
||||
* Removed `setConfig` from `ServiceClientInterface`.
|
||||
* Added `initTransaction` to `ServiceClientInterface`.
|
||||
|
||||
## 0.7.1 - 2015-01-14
|
||||
|
||||
* Fixed and issue where intercepting commands encapsulated by a
|
||||
CommandToRequestIterator could lead to deep recursion. These commands are
|
||||
now skipped and the iterator moves to the next element using a `goto`
|
||||
statement.
|
||||
|
||||
## 0.7.0 - 2014-10-12
|
||||
|
||||
* Updated to use Guzzle 5, and added support for asynchronous results.
|
||||
* Renamed `prepare` event to `prepared`.
|
||||
* Added `init` event.
|
||||
|
||||
## 0.6.0 - 2014-08-08
|
||||
|
||||
* Added a Debug subscriber that can be used to trace through the lifecycle of
|
||||
a command and how it is modified in each event.
|
||||
|
||||
## 0.5.0 - 2014-08-01
|
||||
|
||||
* Rewrote event system so that all exceptions encountered during the transfer
|
||||
of a command are emitted to the "error" event.
|
||||
* No longer wrapping exceptions thrown during the execution of a command.
|
||||
* Added the ability to get a CommandTransaction from events and updating
|
||||
classes to use a CommandTransaction rather than many constructor arguments.
|
||||
* Fixed an issue with sending many commands in parallel
|
||||
* Added `batch()` to ServiceClientInterface for sending commands in batches
|
||||
* Added subscriber to easily mock commands results
|
||||
23
vendor/guzzlehttp/command/LICENSE
vendored
Normal file
23
vendor/guzzlehttp/command/LICENSE
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Michael Dowling <mtdowling@gmail.com>
|
||||
Copyright (c) 2014 Graham Campbell <hello@gjcampbell.co.uk>
|
||||
Copyright (c) 2014 Jeremy Lindblom <jeremeamia@gmail.com>
|
||||
|
||||
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.
|
||||
2
vendor/guzzlehttp/command/Makefile
vendored
Normal file
2
vendor/guzzlehttp/command/Makefile
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
test:
|
||||
vendor/bin/phpunit $(TEST)
|
||||
168
vendor/guzzlehttp/command/README.md
vendored
Normal file
168
vendor/guzzlehttp/command/README.md
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
# Guzzle Commands
|
||||
|
||||
This library uses Guzzle and provides the foundations to create fully-featured
|
||||
web service clients by abstracting Guzzle HTTP *requests* and *responses* into
|
||||
higher-level *commands* and *results*. A *middleware* system, analogous to, but
|
||||
separate from, the one in the HTTP layer may be used to customize client
|
||||
behavior when preparing commands into requests and processing responses into
|
||||
results.
|
||||
|
||||
### Commands
|
||||
|
||||
Key-value pair objects representing an operation of a web service. Commands
|
||||
have a name and a set of parameters.
|
||||
|
||||
### Results
|
||||
|
||||
Key-value pair objects representing the processed result of executing an
|
||||
operation of a web service.
|
||||
|
||||
## Installing
|
||||
|
||||
This project can be installed using [Composer](https://getcomposer.org/):
|
||||
|
||||
```
|
||||
composer require guzzlehttp/command
|
||||
```
|
||||
|
||||
## Service Clients
|
||||
|
||||
Service Clients are web service clients that implement the
|
||||
`GuzzleHttp\Command\ServiceClientInterface` and use an underlying Guzzle HTTP
|
||||
client (`GuzzleHttp\ClientInterface`) to communicate with the service. Service
|
||||
clients create and execute *commands* (`GuzzleHttp\Command\CommandInterface`),
|
||||
which encapsulate operations within the web service, including the operation
|
||||
name and parameters. This library provides a generic implementation of a service
|
||||
client: the `GuzzleHttp\Command\ServiceClient` class.
|
||||
|
||||
## Instantiating a Service Client
|
||||
|
||||
The provided service client implementation (`GuzzleHttp\Command\ServiceClient`)
|
||||
can be instantiated by providing the following arguments:
|
||||
|
||||
1. A fully-configured Guzzle HTTP client that will be used to perform the
|
||||
underlying HTTP requests. That is, an instance of an object implementing
|
||||
`GuzzleHttp\ClientInterface` such as `new GuzzleHttp\Client()`.
|
||||
1. A callable that transforms a Command into a Request. The function should
|
||||
accept a `GuzzleHttp\Command\CommandInterface` object and return a
|
||||
`Psr\Http\Message\RequestInterface` object.
|
||||
1. A callable that transforms a Response into a Result. The function should
|
||||
accept a `Psr\Http\Message\ResponseInterface` object and optionally a
|
||||
`Psr\Http\Message\RequestInterface` object, and return a
|
||||
`GuzzleHttp\Command\ResultInterface` object.
|
||||
1. Optionally, a Guzzle HandlerStack (`GuzzleHttp\HandlerStack`), which can be
|
||||
used to add command-level middleware to the service client.
|
||||
|
||||
Below is an example configured to send and receive JSON payloads:
|
||||
|
||||
```php
|
||||
use GuzzleHttp\Command\CommandInterface;
|
||||
use GuzzleHttp\Command\Result;
|
||||
use GuzzleHttp\Command\ResultInterface;
|
||||
use GuzzleHttp\Command\ServiceClient;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\UriTemplate\UriTemplate;
|
||||
use GuzzleHttp\Utils;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
$client = new ServiceClient(
|
||||
new HttpClient(),
|
||||
function (CommandInterface $command): RequestInterface {
|
||||
return new Request(
|
||||
'POST',
|
||||
UriTemplate::expand('/{command}', ['command' => $command->getName()]),
|
||||
['Accept' => 'application/json', 'Content-Type' => 'application/json'],
|
||||
Utils::jsonEncode($command->toArray())
|
||||
);
|
||||
},
|
||||
function (ResponseInterface $response, RequestInterface $request): ResultInterface {
|
||||
return new Result(
|
||||
Utils::jsonDecode((string) $response->getBody(), true)
|
||||
);
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
## Executing Commands
|
||||
|
||||
Service clients create command objects using the ``getCommand()`` method.
|
||||
|
||||
```php
|
||||
$commandName = 'foo';
|
||||
$arguments = ['baz' => 'bar'];
|
||||
$command = $client->getCommand($commandName, $arguments);
|
||||
```
|
||||
|
||||
After creating a command, you may execute the command using the `execute()`
|
||||
method of the client.
|
||||
|
||||
```php
|
||||
$result = $client->execute($command);
|
||||
```
|
||||
|
||||
The result of executing a command will be an instance of an object implementing
|
||||
`GuzzleHttp\Command\ResultInterface`. Result objects are `ArrayAccess`-ible and
|
||||
contain the data parsed from HTTP response.
|
||||
|
||||
Service clients have magic methods that act as shortcuts to executing commands
|
||||
by name without having to create the ``Command`` object in a separate step
|
||||
before executing it.
|
||||
|
||||
```php
|
||||
$result = $client->foo(['baz' => 'bar']);
|
||||
```
|
||||
|
||||
## Asynchronous Commands
|
||||
|
||||
@TODO Add documentation
|
||||
|
||||
* ``-Async`` suffix for client methods
|
||||
* Promises
|
||||
|
||||
```php
|
||||
// Create and execute an asynchronous command.
|
||||
$command = $command = $client->getCommand('foo', ['baz' => 'bar']);
|
||||
$promise = $client->executeAsync($command);
|
||||
|
||||
// Use asynchronous commands with magic methods.
|
||||
$promise = $client->fooAsync(['baz' => 'bar']);
|
||||
```
|
||||
|
||||
@TODO Add documentation
|
||||
|
||||
* ``wait()``-ing on promises.
|
||||
|
||||
```php
|
||||
$result = $promise->wait();
|
||||
|
||||
echo $result['fizz']; //> 'buzz'
|
||||
```
|
||||
|
||||
## Concurrent Requests
|
||||
|
||||
@TODO Add documentation
|
||||
|
||||
* ``executeAll()``
|
||||
* ``executeAllAsync()``.
|
||||
* Options (``fulfilled``, ``rejected``, ``concurrency``)
|
||||
|
||||
## Middleware: Extending the Client
|
||||
|
||||
Middleware can be added to the service client or underlying HTTP client to
|
||||
implement additional behavior and customize the ``Command``-to-``Result`` and
|
||||
``Request``-to-``Response`` lifecycles, respectively.
|
||||
|
||||
## Security
|
||||
|
||||
If you discover a security vulnerability within this package, please send an email to security@tidelift.com. All security vulnerabilities will be promptly addressed. Please do not disclose security-related issues publicly until a fix has been announced. Please see [Security Policy](https://github.com/guzzle/command/security/policy) for more information.
|
||||
|
||||
## License
|
||||
|
||||
Guzzle is made available under the MIT License (MIT). Please see [License File](LICENSE) for more information.
|
||||
|
||||
## For Enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of Guzzle and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-guzzlehttp-command?utm_source=packagist-guzzlehttp-command&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
55
vendor/guzzlehttp/command/composer.json
vendored
Normal file
55
vendor/guzzlehttp/command/composer.json
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "guzzlehttp/command",
|
||||
"description": "Provides the foundation for building command-based web service clients",
|
||||
"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": "Jeremy Lindblom",
|
||||
"email": "jeremeamia@gmail.com",
|
||||
"homepage": "https://github.com/jeremeamia"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"guzzlehttp/guzzle": "^7.5.1",
|
||||
"guzzlehttp/promises": "^1.5.3 || ^2.0",
|
||||
"guzzlehttp/psr7": "^1.9.1 || ^2.4.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.1",
|
||||
"phpunit/phpunit": "^8.5.19 || ^9.5.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Command\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"bamarni/composer-bin-plugin": true
|
||||
}
|
||||
}
|
||||
}
|
||||
23
vendor/guzzlehttp/command/phpunit.xml.dist
vendored
Normal file
23
vendor/guzzlehttp/command/phpunit.xml.dist
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
backupGlobals="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
convertDeprecationsToExceptions="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
56
vendor/guzzlehttp/command/src/Command.php
vendored
Normal file
56
vendor/guzzlehttp/command/src/Command.php
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
use GuzzleHttp\HandlerStack;
|
||||
|
||||
/**
|
||||
* Default command implementation.
|
||||
*/
|
||||
class Command implements CommandInterface
|
||||
{
|
||||
use HasDataTrait;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var HandlerStack */
|
||||
private $handlerStack;
|
||||
|
||||
/**
|
||||
* @param string $name Name of the command
|
||||
* @param array $args Arguments to pass to the command
|
||||
* @param HandlerStack $handlerStack Stack of middleware for the command
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
array $args = [],
|
||||
HandlerStack $handlerStack = null
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->data = $args;
|
||||
$this->handlerStack = $handlerStack;
|
||||
}
|
||||
|
||||
public function getHandlerStack()
|
||||
{
|
||||
return $this->handlerStack;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function hasParam($name)
|
||||
{
|
||||
return array_key_exists($name, $this->data);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->handlerStack) {
|
||||
$this->handlerStack = clone $this->handlerStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
vendor/guzzlehttp/command/src/CommandInterface.php
vendored
Normal file
40
vendor/guzzlehttp/command/src/CommandInterface.php
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
use GuzzleHttp\HandlerStack;
|
||||
|
||||
/**
|
||||
* A command object encapsulates the input parameters used to control the
|
||||
* creation of a HTTP request and processing of a HTTP response.
|
||||
*
|
||||
* Using the getParams() method will return the input parameters of the command
|
||||
* as an associative array.
|
||||
*/
|
||||
interface CommandInterface extends \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
|
||||
{
|
||||
/**
|
||||
* Retrieves the handler stack specific to this command's execution.
|
||||
*
|
||||
* This can be used to add middleware that is specific to the command instance.
|
||||
*
|
||||
* @return HandlerStack
|
||||
*/
|
||||
public function getHandlerStack();
|
||||
|
||||
/**
|
||||
* Get the name of the command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Check if the command has a parameter by name.
|
||||
*
|
||||
* @param string $name Name of the parameter to check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasParam($name);
|
||||
}
|
||||
10
vendor/guzzlehttp/command/src/Exception/CommandClientException.php
vendored
Normal file
10
vendor/guzzlehttp/command/src/Exception/CommandClientException.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command\Exception;
|
||||
|
||||
/**
|
||||
* Exception encountered when a 4xx level response is received for a request
|
||||
*/
|
||||
class CommandClientException extends CommandException
|
||||
{
|
||||
}
|
||||
107
vendor/guzzlehttp/command/src/Exception/CommandException.php
vendored
Normal file
107
vendor/guzzlehttp/command/src/Exception/CommandException.php
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command\Exception;
|
||||
|
||||
use GuzzleHttp\Command\CommandInterface;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Exception encountered while executing a command.
|
||||
*/
|
||||
class CommandException extends \RuntimeException implements GuzzleException
|
||||
{
|
||||
/** @var CommandInterface */
|
||||
private $command;
|
||||
|
||||
/** @var RequestInterface */
|
||||
private $request;
|
||||
|
||||
/** @var ResponseInterface */
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @return CommandException
|
||||
*/
|
||||
public static function fromPrevious(CommandInterface $command, \Exception $prev)
|
||||
{
|
||||
// If the exception is already a command exception, return it.
|
||||
if ($prev instanceof self && $command === $prev->getCommand()) {
|
||||
return $prev;
|
||||
}
|
||||
|
||||
// If the exception is a RequestException, get the Request and Response.
|
||||
$request = $response = null;
|
||||
if ($prev instanceof RequestException) {
|
||||
$request = $prev->getRequest();
|
||||
$response = $prev->getResponse();
|
||||
}
|
||||
|
||||
// Throw a more specific exception for 4XX or 5XX responses.
|
||||
$class = self::class;
|
||||
$statusCode = $response ? $response->getStatusCode() : 0;
|
||||
if ($statusCode >= 400 && $statusCode < 500) {
|
||||
$class = CommandClientException::class;
|
||||
} elseif ($statusCode >= 500 && $statusCode < 600) {
|
||||
$class = CommandServerException::class;
|
||||
}
|
||||
|
||||
// Prepare the message.
|
||||
$message = 'There was an error executing the '.$command->getName()
|
||||
.' command: '.$prev->getMessage();
|
||||
|
||||
// Create the exception.
|
||||
return new $class($message, $command, $prev, $request, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message Exception message
|
||||
* @param \Exception $previous Previous exception (if any)
|
||||
* @param RequestInterface $request
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function __construct(
|
||||
$message,
|
||||
CommandInterface $command,
|
||||
\Exception $previous = null,
|
||||
RequestInterface $request = null,
|
||||
ResponseInterface $response = null
|
||||
) {
|
||||
$this->command = $command;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
parent::__construct($message, 0, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command that failed.
|
||||
*
|
||||
* @return CommandInterface
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request that caused the exception
|
||||
*
|
||||
* @return RequestInterface|null
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated response
|
||||
*
|
||||
* @return ResponseInterface|null
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
10
vendor/guzzlehttp/command/src/Exception/CommandServerException.php
vendored
Normal file
10
vendor/guzzlehttp/command/src/Exception/CommandServerException.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command\Exception;
|
||||
|
||||
/**
|
||||
* Exception encountered when a 5xx level response is received for a request
|
||||
*/
|
||||
class CommandServerException extends CommandException
|
||||
{
|
||||
}
|
||||
66
vendor/guzzlehttp/command/src/HasDataTrait.php
vendored
Normal file
66
vendor/guzzlehttp/command/src/HasDataTrait.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
/**
|
||||
* Basic collection behavior for Command and Result objects.
|
||||
*
|
||||
* The methods in the class are primarily for implementing the ArrayAccess,
|
||||
* Countable, and IteratorAggregate interfaces.
|
||||
*/
|
||||
trait HasDataTrait
|
||||
{
|
||||
/** @var array Data stored in the collection. */
|
||||
protected $data;
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return print_r($this, true);
|
||||
}
|
||||
|
||||
public function __debugInfo()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->data);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return isset($this->data[$offset]) ? $this->data[$offset] : null;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->data);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
16
vendor/guzzlehttp/command/src/Result.php
vendored
Normal file
16
vendor/guzzlehttp/command/src/Result.php
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
/**
|
||||
* Default command implementation.
|
||||
*/
|
||||
class Result implements ResultInterface
|
||||
{
|
||||
use HasDataTrait;
|
||||
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
10
vendor/guzzlehttp/command/src/ResultInterface.php
vendored
Normal file
10
vendor/guzzlehttp/command/src/ResultInterface.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
/**
|
||||
* An array-like object that represents the result of executing a command.
|
||||
*/
|
||||
interface ResultInterface extends \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
|
||||
{
|
||||
}
|
||||
216
vendor/guzzlehttp/command/src/ServiceClient.php
vendored
Normal file
216
vendor/guzzlehttp/command/src/ServiceClient.php
vendored
Normal file
@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
use GuzzleHttp\ClientInterface as HttpClient;
|
||||
use GuzzleHttp\Command\Exception\CommandException;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Promise;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* The Guzzle ServiceClient serves as the foundation for creating web service
|
||||
* clients that interact with RPC-style APIs.
|
||||
*/
|
||||
class ServiceClient implements ServiceClientInterface
|
||||
{
|
||||
/** @var HttpClient HTTP client used to send requests */
|
||||
private $httpClient;
|
||||
|
||||
/** @var HandlerStack */
|
||||
private $handlerStack;
|
||||
|
||||
/** @var callable */
|
||||
private $commandToRequestTransformer;
|
||||
|
||||
/** @var callable */
|
||||
private $responseToResultTransformer;
|
||||
|
||||
/**
|
||||
* Instantiates a Guzzle ServiceClient for making requests to a web service.
|
||||
*
|
||||
* @param HttpClient $httpClient A fully-configured Guzzle HTTP client that
|
||||
* will be used to perform the underlying HTTP requests.
|
||||
* @param callable $commandToRequestTransformer A callable that transforms
|
||||
* a Command into a Request. The function should accept a
|
||||
* `GuzzleHttp\Command\CommandInterface` object and return a
|
||||
* `Psr\Http\Message\RequestInterface` object.
|
||||
* @param callable $responseToResultTransformer A callable that transforms a
|
||||
* Response into a Result. The function should accept a
|
||||
* `Psr\Http\Message\ResponseInterface` object (and optionally a
|
||||
* `Psr\Http\Message\RequestInterface` object) and return a
|
||||
* `GuzzleHttp\Command\ResultInterface` object.
|
||||
* @param HandlerStack $commandHandlerStack A Guzzle HandlerStack, which can
|
||||
* be used to add command-level middleware to the service client.
|
||||
*/
|
||||
public function __construct(
|
||||
HttpClient $httpClient,
|
||||
callable $commandToRequestTransformer,
|
||||
callable $responseToResultTransformer,
|
||||
HandlerStack $commandHandlerStack = null
|
||||
) {
|
||||
$this->httpClient = $httpClient;
|
||||
$this->commandToRequestTransformer = $commandToRequestTransformer;
|
||||
$this->responseToResultTransformer = $responseToResultTransformer;
|
||||
$this->handlerStack = $commandHandlerStack ?: new HandlerStack();
|
||||
$this->handlerStack->setHandler($this->createCommandHandler());
|
||||
}
|
||||
|
||||
public function getHttpClient()
|
||||
{
|
||||
return $this->httpClient;
|
||||
}
|
||||
|
||||
public function getHandlerStack()
|
||||
{
|
||||
return $this->handlerStack;
|
||||
}
|
||||
|
||||
public function getCommand($name, array $params = [])
|
||||
{
|
||||
return new Command($name, $params, clone $this->handlerStack);
|
||||
}
|
||||
|
||||
public function execute(CommandInterface $command)
|
||||
{
|
||||
return $this->executeAsync($command)->wait();
|
||||
}
|
||||
|
||||
public function executeAsync(CommandInterface $command)
|
||||
{
|
||||
$stack = $command->getHandlerStack() ?: $this->handlerStack;
|
||||
$handler = $stack->resolve();
|
||||
|
||||
return $handler($command);
|
||||
}
|
||||
|
||||
public function executeAll($commands, array $options = [])
|
||||
{
|
||||
// Modify provided callbacks to track results.
|
||||
$results = [];
|
||||
$options['fulfilled'] = function ($v, $k) use (&$results, $options) {
|
||||
if (isset($options['fulfilled'])) {
|
||||
$options['fulfilled']($v, $k);
|
||||
}
|
||||
$results[$k] = $v;
|
||||
};
|
||||
$options['rejected'] = function ($v, $k) use (&$results, $options) {
|
||||
if (isset($options['rejected'])) {
|
||||
$options['rejected']($v, $k);
|
||||
}
|
||||
$results[$k] = $v;
|
||||
};
|
||||
|
||||
// Execute multiple commands synchronously, then sort and return the results.
|
||||
return $this->executeAllAsync($commands, $options)
|
||||
->then(function () use (&$results) {
|
||||
ksort($results);
|
||||
|
||||
return $results;
|
||||
})
|
||||
->wait();
|
||||
}
|
||||
|
||||
public function executeAllAsync($commands, array $options = [])
|
||||
{
|
||||
// Apply default concurrency.
|
||||
if (!isset($options['concurrency'])) {
|
||||
$options['concurrency'] = 25;
|
||||
}
|
||||
|
||||
// Convert the iterator of commands to a generator of promises.
|
||||
$commands = Promise\Create::iterFor($commands);
|
||||
$promises = function () use ($commands) {
|
||||
foreach ($commands as $key => $command) {
|
||||
if (!$command instanceof CommandInterface) {
|
||||
throw new \InvalidArgumentException('The iterator must '
|
||||
.'yield instances of '.CommandInterface::class);
|
||||
}
|
||||
yield $key => $this->executeAsync($command);
|
||||
}
|
||||
};
|
||||
|
||||
// Execute the commands using a pool.
|
||||
return (new Promise\EachPromise($promises(), $options))->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and executes a command for an operation by name.
|
||||
*
|
||||
* @param string $name Name of the command to execute.
|
||||
* @param array $args Arguments to pass to the getCommand method.
|
||||
*
|
||||
* @return ResultInterface|PromiseInterface
|
||||
*
|
||||
* @see \GuzzleHttp\Command\ServiceClientInterface::getCommand
|
||||
*/
|
||||
public function __call($name, array $args)
|
||||
{
|
||||
$args = isset($args[0]) ? $args[0] : [];
|
||||
if (substr($name, -5) === 'Async') {
|
||||
$command = $this->getCommand(substr($name, 0, -5), $args);
|
||||
|
||||
return $this->executeAsync($command);
|
||||
} else {
|
||||
return $this->execute($this->getCommand($name, $args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the main handler for commands that uses the HTTP client.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function createCommandHandler()
|
||||
{
|
||||
return function (CommandInterface $command) {
|
||||
return Promise\Coroutine::of(function () use ($command) {
|
||||
// Prepare the HTTP options.
|
||||
$opts = $command['@http'] ?: [];
|
||||
unset($command['@http']);
|
||||
|
||||
try {
|
||||
// Prepare the request from the command and send it.
|
||||
$request = $this->transformCommandToRequest($command);
|
||||
$promise = $this->httpClient->sendAsync($request, $opts);
|
||||
|
||||
// Create a result from the response.
|
||||
$response = (yield $promise);
|
||||
yield $this->transformResponseToResult($response, $request, $command);
|
||||
} catch (\Exception $e) {
|
||||
throw CommandException::fromPrevious($command, $e);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a Command object into a Request object.
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
private function transformCommandToRequest(CommandInterface $command)
|
||||
{
|
||||
$transform = $this->commandToRequestTransformer;
|
||||
|
||||
return $transform($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a Response object, also using data from the Request object,
|
||||
* into a Result object.
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
private function transformResponseToResult(
|
||||
ResponseInterface $response,
|
||||
RequestInterface $request,
|
||||
CommandInterface $command
|
||||
) {
|
||||
$transform = $this->responseToResultTransformer;
|
||||
|
||||
return $transform($response, $request, $command);
|
||||
}
|
||||
}
|
||||
97
vendor/guzzlehttp/command/src/ServiceClientInterface.php
vendored
Normal file
97
vendor/guzzlehttp/command/src/ServiceClientInterface.php
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Command\Exception\CommandException;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
|
||||
/**
|
||||
* Web service client interface.
|
||||
*/
|
||||
interface ServiceClientInterface
|
||||
{
|
||||
/**
|
||||
* Create a command for an operation name.
|
||||
*
|
||||
* Special keys may be set on the command to control how it behaves.
|
||||
* Implementations SHOULD be able to utilize the following keys or throw
|
||||
* an exception if unable.
|
||||
*
|
||||
* @param string $name Name of the operation to use in the command
|
||||
* @param array $args Arguments to pass to the command
|
||||
*
|
||||
* @return CommandInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException if no command can be found by name
|
||||
*/
|
||||
public function getCommand($name, array $args = []);
|
||||
|
||||
/**
|
||||
* Execute a single command.
|
||||
*
|
||||
* @param CommandInterface $command Command to execute
|
||||
*
|
||||
* @return ResultInterface The result of the executed command
|
||||
*
|
||||
* @throws CommandException
|
||||
*/
|
||||
public function execute(CommandInterface $command);
|
||||
|
||||
/**
|
||||
* Execute a single command asynchronously
|
||||
*
|
||||
* @param CommandInterface $command Command to execute
|
||||
*
|
||||
* @return PromiseInterface A Promise that resolves to a Result.
|
||||
*/
|
||||
public function executeAsync(CommandInterface $command);
|
||||
|
||||
/**
|
||||
* Executes multiple commands concurrently using a fixed pool size.
|
||||
*
|
||||
* @param array|\Iterator $commands Array or iterator that contains
|
||||
* CommandInterface objects to execute with the client.
|
||||
* @param array $options Associative array of options to apply.
|
||||
* - concurrency: (int) Max number of commands to execute concurrently.
|
||||
* - fulfilled: (callable) Function to invoke when a command completes.
|
||||
* - rejected: (callable) Function to invoke when a command fails.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see GuzzleHttp\Command\ServiceClientInterface::createPool for options.
|
||||
*/
|
||||
public function executeAll($commands, array $options = []);
|
||||
|
||||
/**
|
||||
* Executes multiple commands concurrently and asynchronously using a
|
||||
* fixed pool size.
|
||||
*
|
||||
* @param array|\Iterator $commands Array or iterator that contains
|
||||
* CommandInterface objects to execute with the client.
|
||||
* @param array $options Associative array of options to apply.
|
||||
* - concurrency: (int) Max number of commands to execute concurrently.
|
||||
* - fulfilled: (callable) Function to invoke when a command completes.
|
||||
* - rejected: (callable) Function to invoke when a command fails.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*
|
||||
* @see GuzzleHttp\Command\ServiceClientInterface::createPool for options.
|
||||
*/
|
||||
public function executeAllAsync($commands, array $options = []);
|
||||
|
||||
/**
|
||||
* Get the HTTP client used to send requests for the web service client
|
||||
*
|
||||
* @return ClientInterface
|
||||
*/
|
||||
public function getHttpClient();
|
||||
|
||||
/**
|
||||
* Get the HandlerStack which can be used to add middleware to the client.
|
||||
*
|
||||
* @return HandlerStack
|
||||
*/
|
||||
public function getHandlerStack();
|
||||
}
|
||||
16
vendor/guzzlehttp/command/src/ToArrayInterface.php
vendored
Normal file
16
vendor/guzzlehttp/command/src/ToArrayInterface.php
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace GuzzleHttp\Command;
|
||||
|
||||
/**
|
||||
* An object that can be represented as an array
|
||||
*/
|
||||
interface ToArrayInterface
|
||||
{
|
||||
/**
|
||||
* Get the array representation of an object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray();
|
||||
}
|
||||
9
vendor/guzzlehttp/command/vendor-bin/php-cs-fixer/composer.json
vendored
Normal file
9
vendor/guzzlehttp/command/vendor-bin/php-cs-fixer/composer.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"require": {
|
||||
"php": "^7.4 || ^8.0",
|
||||
"friendsofphp/php-cs-fixer": "3.16.0"
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user