update
This commit is contained in:
@@ -22,13 +22,14 @@
|
||||
"php-http/message": "^1.2",
|
||||
"psr/http-client": "^1.0",
|
||||
"psr/http-factory-implementation": "^1.0",
|
||||
"symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0"
|
||||
"symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"guzzlehttp/psr7": "^1.0",
|
||||
"php-http/client-integration-tests": "^3.0",
|
||||
"phpunit/phpunit": "^7.5 || ^9.4",
|
||||
"laminas/laminas-diactoros": "^2.0"
|
||||
"laminas/laminas-diactoros": "^2.0",
|
||||
"php-http/message-factory": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -48,5 +49,10 @@
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"test-ci": "vendor/bin/phpunit --coverage-clover build/coverage.xml"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"php-http/discovery": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
"php-http/httplug": "^1.0 || ^2.0",
|
||||
"php-http/message-factory": "^1.0",
|
||||
"phpspec/phpspec": "^5.1 || ^6.1 || ^7.3",
|
||||
"symfony/phpunit-bridge": "^6.2"
|
||||
"symfony/phpunit-bridge": "^6.4.4 || ^7.0.1",
|
||||
"sebastian/comparator": "^3.0.5 || ^4.0.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
@@ -452,12 +452,21 @@ EOPHP
|
||||
|
||||
private function updateComposerLock(Composer $composer, IOInterface $io)
|
||||
{
|
||||
if (false === $composer->getConfig()->get('lock')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lock = substr(Factory::getComposerFile(), 0, -4).'lock';
|
||||
$composerJson = file_get_contents(Factory::getComposerFile());
|
||||
$lockFile = new JsonFile($lock, null, $io);
|
||||
$locker = ClassDiscovery::safeClassExists(RepositorySet::class)
|
||||
? new Locker($io, $lockFile, $composer->getInstallationManager(), $composerJson)
|
||||
: new Locker($io, $lockFile, $composer->getRepositoryManager(), $composer->getInstallationManager(), $composerJson);
|
||||
|
||||
if (!$locker->isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lockData = $locker->getLockData();
|
||||
$lockData['content-hash'] = Locker::getContentHash($composerJson);
|
||||
$lockFile->write($lockData);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Http\Discovery;
|
||||
|
||||
use Http\Discovery\Exception\NotFoundException as RealNotFoundException;
|
||||
|
||||
/**
|
||||
* Thrown when a discovery does not find any matches.
|
||||
*
|
||||
@@ -9,6 +11,6 @@ namespace Http\Discovery;
|
||||
*
|
||||
* @deprecated since since version 1.0, and will be removed in 2.0. Use {@link \Http\Discovery\Exception\NotFoundException} instead.
|
||||
*/
|
||||
final class NotFoundException extends \Http\Discovery\Exception\NotFoundException
|
||||
final class NotFoundException extends RealNotFoundException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface,
|
||||
private $uriFactory;
|
||||
|
||||
public function __construct(
|
||||
RequestFactoryInterface $requestFactory = null,
|
||||
ResponseFactoryInterface $responseFactory = null,
|
||||
ServerRequestFactoryInterface $serverRequestFactory = null,
|
||||
StreamFactoryInterface $streamFactory = null,
|
||||
UploadedFileFactoryInterface $uploadedFileFactory = null,
|
||||
UriFactoryInterface $uriFactory = null
|
||||
?RequestFactoryInterface $requestFactory = null,
|
||||
?ResponseFactoryInterface $responseFactory = null,
|
||||
?ServerRequestFactoryInterface $serverRequestFactory = null,
|
||||
?StreamFactoryInterface $streamFactory = null,
|
||||
?UploadedFileFactoryInterface $uploadedFileFactory = null,
|
||||
?UriFactoryInterface $uriFactory = null
|
||||
) {
|
||||
$this->requestFactory = $requestFactory;
|
||||
$this->responseFactory = $responseFactory;
|
||||
@@ -98,7 +98,7 @@ class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface,
|
||||
return $factory->createServerRequest(...\func_get_args());
|
||||
}
|
||||
|
||||
public function createServerRequestFromGlobals(array $server = null, array $get = null, array $post = null, array $cookie = null, array $files = null, StreamInterface $body = null): ServerRequestInterface
|
||||
public function createServerRequestFromGlobals(?array $server = null, ?array $get = null, ?array $post = null, ?array $cookie = null, ?array $files = null, ?StreamInterface $body = null): ServerRequestInterface
|
||||
{
|
||||
$server = $server ?? $_SERVER;
|
||||
$request = $this->createServerRequest($server['REQUEST_METHOD'] ?? 'GET', $this->createUriFromGlobals($server), $server);
|
||||
@@ -134,7 +134,7 @@ class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface,
|
||||
return $factory->createStreamFromResource($resource);
|
||||
}
|
||||
|
||||
public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
|
||||
public function createUploadedFile(StreamInterface $stream, ?int $size = null, int $error = \UPLOAD_ERR_OK, ?string $clientFilename = null, ?string $clientMediaType = null): UploadedFileInterface
|
||||
{
|
||||
$factory = $this->uploadedFileFactory ?? $this->setFactory(Psr17FactoryDiscovery::findUploadedFileFactory());
|
||||
|
||||
@@ -148,7 +148,7 @@ class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface,
|
||||
return $factory->createUri(...\func_get_args());
|
||||
}
|
||||
|
||||
public function createUriFromGlobals(array $server = null): UriInterface
|
||||
public function createUriFromGlobals(?array $server = null): UriInterface
|
||||
{
|
||||
return $this->buildUriFromGlobals($this->createUri(''), $server ?? $_SERVER);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Http\Discovery;
|
||||
|
||||
use Http\Discovery\Exception\DiscoveryFailedException;
|
||||
use Http\Discovery\Exception\NotFoundException as RealNotFoundException;
|
||||
use Psr\Http\Message\RequestFactoryInterface;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ServerRequestFactoryInterface;
|
||||
@@ -19,7 +20,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
{
|
||||
private static function createException($type, Exception $e)
|
||||
{
|
||||
return new \Http\Discovery\Exception\NotFoundException(
|
||||
return new RealNotFoundException(
|
||||
'No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation',
|
||||
0,
|
||||
$e
|
||||
@@ -29,7 +30,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return RequestFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findRequestFactory()
|
||||
{
|
||||
@@ -45,7 +46,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return ResponseFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findResponseFactory()
|
||||
{
|
||||
@@ -61,7 +62,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return ServerRequestFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findServerRequestFactory()
|
||||
{
|
||||
@@ -77,7 +78,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return StreamFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findStreamFactory()
|
||||
{
|
||||
@@ -93,7 +94,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return UploadedFileFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findUploadedFileFactory()
|
||||
{
|
||||
@@ -109,7 +110,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return UriFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function findUriFactory()
|
||||
{
|
||||
@@ -125,7 +126,7 @@ final class Psr17FactoryDiscovery extends ClassDiscovery
|
||||
/**
|
||||
* @return UriFactoryInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*
|
||||
* @deprecated This will be removed in 2.0. Consider using the findUriFactory() method.
|
||||
*/
|
||||
|
||||
@@ -25,14 +25,21 @@ class Psr18Client extends Psr17Factory implements ClientInterface
|
||||
private $client;
|
||||
|
||||
public function __construct(
|
||||
ClientInterface $client = null,
|
||||
RequestFactoryInterface $requestFactory = null,
|
||||
ResponseFactoryInterface $responseFactory = null,
|
||||
ServerRequestFactoryInterface $serverRequestFactory = null,
|
||||
StreamFactoryInterface $streamFactory = null,
|
||||
UploadedFileFactoryInterface $uploadedFileFactory = null,
|
||||
UriFactoryInterface $uriFactory = null
|
||||
?ClientInterface $client = null,
|
||||
?RequestFactoryInterface $requestFactory = null,
|
||||
?ResponseFactoryInterface $responseFactory = null,
|
||||
?ServerRequestFactoryInterface $serverRequestFactory = null,
|
||||
?StreamFactoryInterface $streamFactory = null,
|
||||
?UploadedFileFactoryInterface $uploadedFileFactory = null,
|
||||
?UriFactoryInterface $uriFactory = null
|
||||
) {
|
||||
$requestFactory ?? $requestFactory = $client instanceof RequestFactoryInterface ? $client : null;
|
||||
$responseFactory ?? $responseFactory = $client instanceof ResponseFactoryInterface ? $client : null;
|
||||
$serverRequestFactory ?? $serverRequestFactory = $client instanceof ServerRequestFactoryInterface ? $client : null;
|
||||
$streamFactory ?? $streamFactory = $client instanceof StreamFactoryInterface ? $client : null;
|
||||
$uploadedFileFactory ?? $uploadedFileFactory = $client instanceof UploadedFileFactoryInterface ? $client : null;
|
||||
$uriFactory ?? $uriFactory = $client instanceof UriFactoryInterface ? $client : null;
|
||||
|
||||
parent::__construct($requestFactory, $responseFactory, $serverRequestFactory, $streamFactory, $uploadedFileFactory, $uriFactory);
|
||||
|
||||
$this->client = $client ?? Psr18ClientDiscovery::find();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Http\Discovery;
|
||||
|
||||
use Http\Discovery\Exception\DiscoveryFailedException;
|
||||
use Http\Discovery\Exception\NotFoundException as RealNotFoundException;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
|
||||
/**
|
||||
@@ -17,14 +18,14 @@ final class Psr18ClientDiscovery extends ClassDiscovery
|
||||
*
|
||||
* @return ClientInterface
|
||||
*
|
||||
* @throws Exception\NotFoundException
|
||||
* @throws RealNotFoundException
|
||||
*/
|
||||
public static function find()
|
||||
{
|
||||
try {
|
||||
$client = static::findOneByType(ClientInterface::class);
|
||||
} catch (DiscoveryFailedException $e) {
|
||||
throw new \Http\Discovery\Exception\NotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter".', 0, $e);
|
||||
throw new RealNotFoundException('No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter".', 0, $e);
|
||||
}
|
||||
|
||||
return static::instantiateClass($client);
|
||||
|
||||
@@ -78,7 +78,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
|
||||
['class' => React::class, 'condition' => React::class],
|
||||
],
|
||||
HttpClient::class => [
|
||||
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, [self::class, 'isPsr17FactoryInstalled']]],
|
||||
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, [self::class, 'isPsr17FactoryInstalled'], [self::class, 'isSymfonyImplementingHttpClient']]],
|
||||
['class' => Guzzle7::class, 'condition' => Guzzle7::class],
|
||||
['class' => Guzzle6::class, 'condition' => Guzzle6::class],
|
||||
['class' => Guzzle5::class, 'condition' => Guzzle5::class],
|
||||
@@ -158,6 +158,11 @@ final class CommonClassesStrategy implements DiscoveryStrategy
|
||||
return defined('GuzzleHttp\ClientInterface::MAJOR_VERSION');
|
||||
}
|
||||
|
||||
public static function isSymfonyImplementingHttpClient()
|
||||
{
|
||||
return is_subclass_of(SymfonyHttplug::class, HttpClient::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used as a condition.
|
||||
*
|
||||
|
||||
@@ -26,7 +26,7 @@ class HttpException extends RequestException
|
||||
$message,
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response,
|
||||
\Exception $previous = null
|
||||
?\Exception $previous = null
|
||||
) {
|
||||
parent::__construct($message, $request, $previous);
|
||||
|
||||
@@ -50,7 +50,7 @@ class HttpException extends RequestException
|
||||
public static function create(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response,
|
||||
\Exception $previous = null
|
||||
?\Exception $previous = null
|
||||
) {
|
||||
$message = sprintf(
|
||||
'[url] %s [http method] %s [status code] %s [reason phrase] %s',
|
||||
|
||||
@@ -19,7 +19,7 @@ class NetworkException extends TransferException implements PsrNetworkException
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct($message, RequestInterface $request, \Exception $previous = null)
|
||||
public function __construct($message, RequestInterface $request, ?\Exception $previous = null)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@ trait RequestAwareTrait
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRequest(): RequestInterface
|
||||
{
|
||||
return $this->request;
|
||||
|
||||
@@ -20,7 +20,7 @@ class RequestException extends TransferException implements PsrRequestException
|
||||
/**
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct($message, RequestInterface $request, \Exception $previous = null)
|
||||
public function __construct($message, RequestInterface $request, ?\Exception $previous = null)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
|
||||
|
||||
@@ -18,10 +18,7 @@ final class HttpFulfilledPromise implements Promise
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||
{
|
||||
if (null === $onFulfilled) {
|
||||
return $this;
|
||||
@@ -34,17 +31,11 @@ final class HttpFulfilledPromise implements Promise
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return Promise::FULFILLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wait($unwrap = true)
|
||||
{
|
||||
if ($unwrap) {
|
||||
|
||||
@@ -17,10 +17,7 @@ final class HttpRejectedPromise implements Promise
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||
{
|
||||
if (null === $onRejected) {
|
||||
return $this;
|
||||
@@ -38,17 +35,11 @@ final class HttpRejectedPromise implements Promise
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return Promise::REJECTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wait($unwrap = true)
|
||||
{
|
||||
if ($unwrap) {
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0",
|
||||
"php": "^7.2 || ^8.0",
|
||||
"clue/stream-filter": "^1.5",
|
||||
"php-http/message-factory": "^1.0.2",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
"psr/http-message": "^1.1 || ^2.0"
|
||||
},
|
||||
"provide": {
|
||||
"php-http/message-factory-implementation": "1.0"
|
||||
@@ -26,10 +25,11 @@
|
||||
"require-dev": {
|
||||
"ext-zlib": "*",
|
||||
"ergebnis/composer-normalize": "^2.6",
|
||||
"guzzlehttp/psr7": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.0 || ^2.0",
|
||||
"php-http/message-factory": "^1.0.2",
|
||||
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.1",
|
||||
"slim/slim": "^3.0",
|
||||
"laminas/laminas-diactoros": "^2.0"
|
||||
"laminas/laminas-diactoros": "^2.0 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-zlib": "Used with compressor/decompressor streams",
|
||||
|
||||
@@ -27,9 +27,6 @@ final class AutoBasicAuth implements Authentication
|
||||
$this->shouldRemoveUserInfo = (bool) $shouldRremoveUserInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
$uri = $request->getUri();
|
||||
|
||||
@@ -32,9 +32,6 @@ final class BasicAuth implements Authentication
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
$header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password)));
|
||||
|
||||
@@ -25,9 +25,6 @@ final class Bearer implements Authentication
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
$header = sprintf('Bearer %s', $this->token);
|
||||
|
||||
@@ -33,9 +33,6 @@ final class Chain implements Authentication
|
||||
$this->authenticationChain = $authenticationChain;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
foreach ($this->authenticationChain as $authentication) {
|
||||
|
||||
@@ -26,9 +26,6 @@ class Header implements Authentication
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
return $request->withHeader($this->name, $this->value);
|
||||
|
||||
@@ -27,7 +27,7 @@ final class Matching implements Authentication
|
||||
*/
|
||||
private $matcher;
|
||||
|
||||
public function __construct(Authentication $authentication, callable $matcher = null)
|
||||
public function __construct(Authentication $authentication, ?callable $matcher = null)
|
||||
{
|
||||
if (is_null($matcher)) {
|
||||
$matcher = function () {
|
||||
@@ -39,9 +39,6 @@ final class Matching implements Authentication
|
||||
$this->matcher = new CallbackRequestMatcher($matcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
if ($this->matcher->matches($request)) {
|
||||
|
||||
@@ -25,9 +25,6 @@ final class QueryParam implements Authentication
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
$uri = $request->getUri();
|
||||
|
||||
@@ -29,9 +29,6 @@ final class RequestConditional implements Authentication
|
||||
$this->authentication = $authentication;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
if ($this->requestMatcher->matches($request)) {
|
||||
|
||||
@@ -42,9 +42,6 @@ final class Wsse implements Authentication
|
||||
$this->hashAlgorithm = $hashAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function authenticate(RequestInterface $request)
|
||||
{
|
||||
$nonce = substr(md5(uniqid(uniqid().'_', true)), 0, 16);
|
||||
|
||||
@@ -73,7 +73,7 @@ final class Cookie
|
||||
$path = null,
|
||||
$secure = false,
|
||||
$httpOnly = false,
|
||||
\DateTime $expires = null
|
||||
?\DateTime $expires = null
|
||||
) {
|
||||
$this->validateName($name);
|
||||
$this->validateValue($value);
|
||||
@@ -109,7 +109,7 @@ final class Cookie
|
||||
$path = null,
|
||||
$secure = false,
|
||||
$httpOnly = false,
|
||||
\DateTime $expires = null
|
||||
?\DateTime $expires = null
|
||||
) {
|
||||
$cookie = new self('name', null, null, $domain, $path, $secure, $httpOnly, $expires);
|
||||
$cookie->name = $name;
|
||||
@@ -228,7 +228,7 @@ final class Cookie
|
||||
*
|
||||
* @return Cookie
|
||||
*/
|
||||
public function withExpires(\DateTime $expires = null)
|
||||
public function withExpires(?\DateTime $expires = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->expires = $expires;
|
||||
@@ -511,7 +511,9 @@ final class Cookie
|
||||
*/
|
||||
private function normalizePath($path)
|
||||
{
|
||||
$path = rtrim($path, '/');
|
||||
if (null !== $path) {
|
||||
$path = rtrim($path, '/');
|
||||
}
|
||||
|
||||
if (empty($path) or '/' !== substr($path, 0, 1)) {
|
||||
$path = '/';
|
||||
|
||||
@@ -192,18 +192,12 @@ final class CookieJar implements \Countable, \IteratorAggregate
|
||||
$this->cookies = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return $this->cookies->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
|
||||
@@ -20,26 +20,18 @@ trait MessageDecorator
|
||||
*
|
||||
* Since the underlying Message is immutable as well
|
||||
* exposing it is not an issue, because it's state cannot be altered
|
||||
*
|
||||
* @return MessageInterface
|
||||
*/
|
||||
public function getMessage()
|
||||
public function getMessage(): MessageInterface
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProtocolVersion()
|
||||
public function getProtocolVersion(): string
|
||||
{
|
||||
return $this->message->getProtocolVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withProtocolVersion($version)
|
||||
public function withProtocolVersion(string $version): MessageInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withProtocolVersion($version);
|
||||
@@ -47,42 +39,27 @@ trait MessageDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeaders()
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->message->getHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasHeader($header)
|
||||
public function hasHeader(string $header): bool
|
||||
{
|
||||
return $this->message->hasHeader($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeader($header)
|
||||
public function getHeader(string $header): array
|
||||
{
|
||||
return $this->message->getHeader($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeaderLine($header)
|
||||
public function getHeaderLine(string $header): string
|
||||
{
|
||||
return $this->message->getHeaderLine($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withHeader($header, $value)
|
||||
public function withHeader(string $header, $value): MessageInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withHeader($header, $value);
|
||||
@@ -90,10 +67,7 @@ trait MessageDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withAddedHeader($header, $value)
|
||||
public function withAddedHeader(string $header, $value): MessageInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withAddedHeader($header, $value);
|
||||
@@ -101,10 +75,7 @@ trait MessageDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withoutHeader($header)
|
||||
public function withoutHeader(string $header): MessageInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withoutHeader($header);
|
||||
@@ -112,18 +83,12 @@ trait MessageDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBody()
|
||||
public function getBody(): StreamInterface
|
||||
{
|
||||
return $this->message->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withBody(StreamInterface $body)
|
||||
public function withBody(StreamInterface $body): MessageInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withBody($body);
|
||||
|
||||
@@ -16,10 +16,8 @@ trait RequestDecorator
|
||||
|
||||
/**
|
||||
* Exchanges the underlying request with another.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function withRequest(RequestInterface $request)
|
||||
public function withRequest(RequestInterface $request): RequestInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $request;
|
||||
@@ -27,18 +25,12 @@ trait RequestDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRequestTarget()
|
||||
public function getRequestTarget(): string
|
||||
{
|
||||
return $this->message->getRequestTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withRequestTarget($requestTarget)
|
||||
public function withRequestTarget(string $requestTarget): RequestInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withRequestTarget($requestTarget);
|
||||
@@ -46,18 +38,12 @@ trait RequestDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMethod()
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->message->getMethod();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withMethod($method)
|
||||
public function withMethod(string $method): RequestInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withMethod($method);
|
||||
@@ -65,18 +51,12 @@ trait RequestDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUri()
|
||||
public function getUri(): UriInterface
|
||||
{
|
||||
return $this->message->getUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withUri(UriInterface $uri, $preserveHost = false)
|
||||
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withUri($uri, $preserveHost);
|
||||
|
||||
@@ -15,10 +15,8 @@ trait ResponseDecorator
|
||||
|
||||
/**
|
||||
* Exchanges the underlying response with another.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function withResponse(ResponseInterface $response)
|
||||
public function withResponse(ResponseInterface $response): ResponseInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $response;
|
||||
@@ -26,18 +24,12 @@ trait ResponseDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return $this->message->getStatusCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function withStatus($code, $reasonPhrase = '')
|
||||
public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->message = $this->message->withStatus($code, $reasonPhrase);
|
||||
@@ -45,10 +37,7 @@ trait ResponseDecorator
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReasonPhrase()
|
||||
public function getReasonPhrase(): string
|
||||
{
|
||||
return $this->message->getReasonPhrase();
|
||||
}
|
||||
|
||||
@@ -16,122 +16,77 @@ trait StreamDecorator
|
||||
*/
|
||||
protected $stream;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->stream->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
public function close(): void
|
||||
{
|
||||
$this->stream->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
return $this->stream->detach();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return $this->stream->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
public function tell(): int
|
||||
{
|
||||
return $this->stream->tell();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
public function eof(): bool
|
||||
{
|
||||
return $this->stream->eof();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSeekable()
|
||||
public function isSeekable(): bool
|
||||
{
|
||||
return $this->stream->isSeekable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
public function seek(int $offset, int $whence = SEEK_SET): void
|
||||
{
|
||||
$this->stream->seek($offset, $whence);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->stream->rewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
public function isWritable(): bool
|
||||
{
|
||||
return $this->stream->isWritable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($string)
|
||||
public function write(string $string): int
|
||||
{
|
||||
return $this->stream->write($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable()
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return $this->stream->isReadable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
public function read(int $length): string
|
||||
{
|
||||
return $this->stream->read($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
public function getContents(): string
|
||||
{
|
||||
return $this->stream->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
public function getMetadata(?string $key = null)
|
||||
{
|
||||
return $this->stream->getMetadata($key);
|
||||
}
|
||||
|
||||
@@ -9,26 +9,17 @@ namespace Http\Message\Encoding;
|
||||
*/
|
||||
class ChunkStream extends FilteredStream
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'chunk';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'dechunk';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function fill()
|
||||
protected function fill(): void
|
||||
{
|
||||
parent::fill();
|
||||
|
||||
|
||||
@@ -27,18 +27,12 @@ class CompressStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
@@ -11,18 +11,12 @@ namespace Http\Message\Encoding;
|
||||
*/
|
||||
class DechunkStream extends FilteredStream
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'dechunk';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'chunk';
|
||||
}
|
||||
|
||||
@@ -27,18 +27,12 @@ class DecompressStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 15, 'level' => $level]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
@@ -23,18 +23,12 @@ class DeflateStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@ namespace Http\Message\Encoding\Filter;
|
||||
*/
|
||||
class Chunk extends \php_user_filter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function filter($in, $out, &$consumed, $closing)
|
||||
public function filter($in, $out, &$consumed, $closing): int
|
||||
{
|
||||
while ($bucket = stream_bucket_make_writeable($in)) {
|
||||
$lenbucket = stream_bucket_new($this->stream, dechex($bucket->datalen)."\r\n");
|
||||
|
||||
@@ -75,10 +75,7 @@ abstract class FilteredStream implements StreamInterface
|
||||
$this->stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
public function read(int $length): string
|
||||
{
|
||||
if (strlen($this->buffer) >= $length) {
|
||||
$read = substr($this->buffer, 0, $length);
|
||||
@@ -101,10 +98,7 @@ abstract class FilteredStream implements StreamInterface
|
||||
return $read.$this->read($length - strlen($read));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
public function eof(): bool
|
||||
{
|
||||
return $this->stream->eof() && '' === $this->buffer;
|
||||
}
|
||||
@@ -116,7 +110,7 @@ abstract class FilteredStream implements StreamInterface
|
||||
* This allow to get last data in the PHP buffer otherwise this
|
||||
* bug is present : https://bugs.php.net/bug.php?id=48725
|
||||
*/
|
||||
protected function fill()
|
||||
protected function fill(): void
|
||||
{
|
||||
$readFilterCallback = $this->readFilterCallback;
|
||||
$this->buffer .= $readFilterCallback($this->stream->read(self::BUFFER_SIZE));
|
||||
@@ -126,10 +120,7 @@ abstract class FilteredStream implements StreamInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
public function getContents(): string
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
@@ -149,15 +140,12 @@ abstract class FilteredStream implements StreamInterface
|
||||
/**
|
||||
* Always returns null because we can't tell the size of a stream when we filter.
|
||||
*/
|
||||
public function getSize()
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getContents();
|
||||
}
|
||||
@@ -167,24 +155,24 @@ abstract class FilteredStream implements StreamInterface
|
||||
*
|
||||
* We would need to buffer and process everything to allow seeking.
|
||||
*/
|
||||
public function isSeekable()
|
||||
public function isSeekable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Filtered streams are not seekable and can thus not be rewound.
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
@trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED);
|
||||
$this->doRewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Filtered streams are not seekable.
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
public function seek(int $offset, int $whence = SEEK_SET): void
|
||||
{
|
||||
@trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version', E_USER_DEPRECATED);
|
||||
$this->doSeek($offset, $whence);
|
||||
@@ -193,11 +181,9 @@ abstract class FilteredStream implements StreamInterface
|
||||
/**
|
||||
* Returns the read filter name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated since version 1.5, will be removed in 2.0
|
||||
*/
|
||||
public function getReadFilter()
|
||||
public function getReadFilter(): string
|
||||
{
|
||||
@trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
|
||||
|
||||
@@ -206,19 +192,15 @@ abstract class FilteredStream implements StreamInterface
|
||||
|
||||
/**
|
||||
* Returns the write filter name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function readFilter();
|
||||
abstract protected function readFilter(): string;
|
||||
|
||||
/**
|
||||
* Returns the write filter name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated since version 1.5, will be removed in 2.0
|
||||
*/
|
||||
public function getWriteFilter()
|
||||
public function getWriteFilter(): string
|
||||
{
|
||||
@trigger_error('The '.__CLASS__.'::'.__METHOD__.' method is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
|
||||
|
||||
@@ -227,8 +209,6 @@ abstract class FilteredStream implements StreamInterface
|
||||
|
||||
/**
|
||||
* Returns the write filter name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function writeFilter();
|
||||
abstract protected function writeFilter(): string;
|
||||
}
|
||||
|
||||
@@ -27,18 +27,12 @@ class GzipDecodeStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31, 'level' => $level]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
@@ -27,18 +27,12 @@ class GzipEncodeStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => 31]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
@@ -27,18 +27,12 @@ class InflateStream extends FilteredStream
|
||||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), ['window' => -15, 'level' => $level]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFilter()
|
||||
protected function readFilter(): string
|
||||
{
|
||||
return 'zlib.inflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function writeFilter()
|
||||
protected function writeFilter(): string
|
||||
{
|
||||
return 'zlib.deflate';
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ use Psr\Http\Message\ResponseInterface;
|
||||
*/
|
||||
class CurlCommandFormatter implements Formatter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
$command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment('')));
|
||||
@@ -60,9 +57,6 @@ class CurlCommandFormatter implements Formatter
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
return '';
|
||||
|
||||
@@ -36,9 +36,6 @@ class FullHttpMessageFormatter implements Formatter
|
||||
$this->binaryDetectionRegex = $binaryDetectionRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
$message = sprintf(
|
||||
@@ -55,9 +52,6 @@ class FullHttpMessageFormatter implements Formatter
|
||||
return $this->addBody($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
$message = sprintf(
|
||||
|
||||
@@ -14,9 +14,6 @@ use Psr\Http\Message\ResponseInterface;
|
||||
*/
|
||||
class SimpleFormatter implements Formatter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
return sprintf(
|
||||
@@ -27,9 +24,6 @@ class SimpleFormatter implements Formatter
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
return sprintf(
|
||||
|
||||
@@ -9,6 +9,10 @@ use Laminas\Diactoros\Response as LaminasResponse;
|
||||
use Zend\Diactoros\Request as ZendRequest;
|
||||
use Zend\Diactoros\Response as ZendResponse;
|
||||
|
||||
if (!interface_exists(MessageFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Diactoros messages.
|
||||
*
|
||||
@@ -28,9 +32,6 @@ final class DiactorosMessageFactory implements MessageFactory
|
||||
$this->streamFactory = new DiactorosStreamFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createRequest(
|
||||
$method,
|
||||
$uri,
|
||||
@@ -55,9 +56,6 @@ final class DiactorosMessageFactory implements MessageFactory
|
||||
))->withProtocolVersion($protocolVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createResponse(
|
||||
$statusCode = 200,
|
||||
$reasonPhrase = null,
|
||||
|
||||
@@ -6,6 +6,10 @@ use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Http\Message\MessageFactory;
|
||||
|
||||
if (!interface_exists(MessageFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Guzzle messages.
|
||||
*
|
||||
@@ -15,9 +19,6 @@ use Http\Message\MessageFactory;
|
||||
*/
|
||||
final class GuzzleMessageFactory implements MessageFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createRequest(
|
||||
$method,
|
||||
$uri,
|
||||
@@ -34,9 +35,6 @@ final class GuzzleMessageFactory implements MessageFactory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createResponse(
|
||||
$statusCode = 200,
|
||||
$reasonPhrase = null,
|
||||
|
||||
@@ -9,6 +9,10 @@ use Slim\Http\Headers;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
if (!interface_exists(MessageFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimMessageFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Slim 3 messages.
|
||||
*
|
||||
@@ -34,9 +38,6 @@ final class SlimMessageFactory implements MessageFactory
|
||||
$this->uriFactory = new SlimUriFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createRequest(
|
||||
$method,
|
||||
$uri,
|
||||
@@ -55,9 +56,6 @@ final class SlimMessageFactory implements MessageFactory
|
||||
))->withProtocolVersion($protocolVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createResponse(
|
||||
$statusCode = 200,
|
||||
$reasonPhrase = null,
|
||||
|
||||
@@ -22,9 +22,6 @@ final class CallbackRequestMatcher implements RequestMatcher
|
||||
$this->callback = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matches(RequestInterface $request)
|
||||
{
|
||||
return (bool) call_user_func($this->callback, $request);
|
||||
|
||||
@@ -31,9 +31,6 @@ final class RegexRequestMatcher implements RequestMatcher
|
||||
$this->regex = $regex;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matches(RequestInterface $request)
|
||||
{
|
||||
return (bool) preg_match($this->regex, (string) $request->getUri());
|
||||
|
||||
@@ -51,8 +51,6 @@ final class RequestMatcher implements RequestMatcherInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function matches(RequestInterface $request)
|
||||
|
||||
@@ -17,7 +17,7 @@ class BufferedStream implements StreamInterface
|
||||
/** @var resource The buffered resource used to seek previous data */
|
||||
private $resource;
|
||||
|
||||
/** @var int size of the stream if available */
|
||||
/** @var int|null size of the stream if available */
|
||||
private $size;
|
||||
|
||||
/** @var StreamInterface The underlying stream decorated by this class */
|
||||
@@ -49,10 +49,7 @@ class BufferedStream implements StreamInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
try {
|
||||
$this->rewind();
|
||||
@@ -60,15 +57,10 @@ class BufferedStream implements StreamInterface
|
||||
return $this->getContents();
|
||||
} catch (\Throwable $throwable) {
|
||||
return '';
|
||||
} catch (\Exception $exception) { // Layer to be BC with PHP 5, remove this when we only support PHP 7+
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
public function close(): void
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot close on a detached stream');
|
||||
@@ -78,13 +70,10 @@ class BufferedStream implements StreamInterface
|
||||
fclose($this->resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Force reading the remaining data of the stream
|
||||
@@ -98,13 +87,10 @@ class BufferedStream implements StreamInterface
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
public function getSize(): ?int
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null === $this->size && $this->stream->eof()) {
|
||||
@@ -114,22 +100,21 @@ class BufferedStream implements StreamInterface
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
public function tell(): int
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot tell on a detached stream');
|
||||
}
|
||||
|
||||
return ftell($this->resource);
|
||||
$tell = ftell($this->resource);
|
||||
if (false === $tell) {
|
||||
throw new \RuntimeException('ftell failed');
|
||||
}
|
||||
|
||||
return $tell;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eof()
|
||||
public function eof(): bool
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot call eof on a detached stream');
|
||||
@@ -139,18 +124,12 @@ class BufferedStream implements StreamInterface
|
||||
return $this->stream->eof() && (ftell($this->resource) === $this->written);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isSeekable()
|
||||
public function isSeekable(): bool
|
||||
{
|
||||
return null !== $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
public function seek(int $offset, int $whence = SEEK_SET): void
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot seek on a detached stream');
|
||||
@@ -159,10 +138,7 @@ class BufferedStream implements StreamInterface
|
||||
fseek($this->resource, $offset, $whence);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot rewind on a detached stream');
|
||||
@@ -171,34 +147,22 @@ class BufferedStream implements StreamInterface
|
||||
rewind($this->resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable()
|
||||
public function isWritable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($string)
|
||||
public function write(string $string): int
|
||||
{
|
||||
throw new \RuntimeException('Cannot write on this stream');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable()
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return null !== $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
public function read(int $length): string
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot read on a detached stream');
|
||||
@@ -206,6 +170,9 @@ class BufferedStream implements StreamInterface
|
||||
if ($length < 0) {
|
||||
throw new \InvalidArgumentException('Can not read a negative amount of bytes');
|
||||
}
|
||||
if (0 === $length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$read = '';
|
||||
|
||||
@@ -213,6 +180,9 @@ class BufferedStream implements StreamInterface
|
||||
if (ftell($this->resource) !== $this->written) {
|
||||
$read = fread($this->resource, $length);
|
||||
}
|
||||
if (false === $read) {
|
||||
throw new \RuntimeException('Failed to read from resource');
|
||||
}
|
||||
|
||||
$bytesRead = strlen($read);
|
||||
|
||||
@@ -227,10 +197,7 @@ class BufferedStream implements StreamInterface
|
||||
return $read;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContents()
|
||||
public function getContents(): string
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
throw new \RuntimeException('Cannot read on a detached stream');
|
||||
@@ -245,17 +212,14 @@ class BufferedStream implements StreamInterface
|
||||
return $read;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
public function getMetadata(?string $key = null)
|
||||
{
|
||||
if (null === $this->resource) {
|
||||
if (null === $key) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$metadata = stream_get_meta_data($this->resource);
|
||||
@@ -265,7 +229,7 @@ class BufferedStream implements StreamInterface
|
||||
}
|
||||
|
||||
if (!array_key_exists($key, $metadata)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $metadata[$key];
|
||||
|
||||
@@ -7,6 +7,10 @@ use Laminas\Diactoros\Stream as LaminasStream;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Zend\Diactoros\Stream as ZendStream;
|
||||
|
||||
if (!interface_exists(StreamFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Diactoros streams.
|
||||
*
|
||||
@@ -16,9 +20,6 @@ use Zend\Diactoros\Stream as ZendStream;
|
||||
*/
|
||||
final class DiactorosStreamFactory implements StreamFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createStream($body = null)
|
||||
{
|
||||
if ($body instanceof StreamInterface) {
|
||||
|
||||
@@ -5,6 +5,10 @@ namespace Http\Message\StreamFactory;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use Http\Message\StreamFactory;
|
||||
|
||||
if (!interface_exists(StreamFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Guzzle streams.
|
||||
*
|
||||
@@ -14,15 +18,13 @@ use Http\Message\StreamFactory;
|
||||
*/
|
||||
final class GuzzleStreamFactory implements StreamFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createStream($body = null)
|
||||
{
|
||||
if (class_exists(Utils::class)) {
|
||||
return Utils::streamFor($body);
|
||||
}
|
||||
|
||||
// legacy support for guzzle/psr7 1.*
|
||||
return \GuzzleHttp\Psr7\stream_for($body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ use Http\Message\StreamFactory;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Slim\Http\Stream;
|
||||
|
||||
if (!interface_exists(StreamFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimStreamFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Slim 3 streams.
|
||||
*
|
||||
@@ -15,9 +19,6 @@ use Slim\Http\Stream;
|
||||
*/
|
||||
final class SlimStreamFactory implements StreamFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createStream($body = null)
|
||||
{
|
||||
if ($body instanceof StreamInterface) {
|
||||
|
||||
@@ -7,6 +7,10 @@ use Laminas\Diactoros\Uri as LaminasUri;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Zend\Diactoros\Uri as ZendUri;
|
||||
|
||||
if (!interface_exists(UriFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\DiactorosUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Diactoros URI.
|
||||
*
|
||||
@@ -16,9 +20,6 @@ use Zend\Diactoros\Uri as ZendUri;
|
||||
*/
|
||||
final class DiactorosUriFactory implements UriFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createUri($uri)
|
||||
{
|
||||
if ($uri instanceof UriInterface) {
|
||||
|
||||
@@ -7,6 +7,10 @@ use Http\Message\UriFactory;
|
||||
|
||||
use function GuzzleHttp\Psr7\uri_for;
|
||||
|
||||
if (!interface_exists(UriFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\GuzzleUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Guzzle URI.
|
||||
*
|
||||
@@ -16,9 +20,6 @@ use function GuzzleHttp\Psr7\uri_for;
|
||||
*/
|
||||
final class GuzzleUriFactory implements UriFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createUri($uri)
|
||||
{
|
||||
if (class_exists(Utils::class)) {
|
||||
|
||||
@@ -6,6 +6,10 @@ use Http\Message\UriFactory;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Slim\Http\Uri;
|
||||
|
||||
if (!interface_exists(UriFactory::class)) {
|
||||
throw new \LogicException('You cannot use "Http\Message\MessageFactory\SlimUriFactory" as the "php-http/message-factory" package is not installed. Try running "composer require php-http/message-factory". Note that this package is deprecated, use "psr/http-factory" instead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Slim 3 URI.
|
||||
*
|
||||
@@ -15,9 +19,6 @@ use Slim\Http\Uri;
|
||||
*/
|
||||
final class SlimUriFactory implements UriFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createUri($uri)
|
||||
{
|
||||
if ($uri instanceof UriInterface) {
|
||||
|
||||
@@ -6,30 +6,23 @@ namespace Http\Promise;
|
||||
* A promise already fulfilled.
|
||||
*
|
||||
* @author Joel Wurtz <joel.wurtz@gmail.com>
|
||||
*
|
||||
* @template-covariant T
|
||||
*
|
||||
* @implements Promise<T>
|
||||
*/
|
||||
final class FulfilledPromise implements Promise
|
||||
{
|
||||
/**
|
||||
* @var T
|
||||
* @var mixed
|
||||
*/
|
||||
private $result;
|
||||
|
||||
/**
|
||||
* @param T $result
|
||||
* @param mixed $result
|
||||
*/
|
||||
public function __construct($result)
|
||||
{
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||
{
|
||||
if (null === $onFulfilled) {
|
||||
return $this;
|
||||
@@ -42,21 +35,17 @@ final class FulfilledPromise implements Promise
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return Promise::FULFILLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wait($unwrap = true)
|
||||
{
|
||||
if ($unwrap) {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace Http\Promise;
|
||||
*
|
||||
* @author Joel Wurtz <joel.wurtz@gmail.com>
|
||||
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
|
||||
*
|
||||
* @template-covariant T
|
||||
*/
|
||||
interface Promise
|
||||
{
|
||||
@@ -38,14 +36,12 @@ interface Promise
|
||||
* If you do not care about one of the cases, you can set the corresponding callable to null
|
||||
* The callback will be called when the value arrived and never more than once.
|
||||
*
|
||||
* @param callable(T): V|null $onFulfilled called when a response will be available
|
||||
* @param callable(\Exception): V|null $onRejected called when an exception occurs
|
||||
* @param callable|null $onFulfilled called when a response will be available
|
||||
* @param callable|null $onRejected called when an exception occurs
|
||||
*
|
||||
* @return Promise<V> a new resolved promise with value of the executed callback (onFulfilled / onRejected)
|
||||
*
|
||||
* @template V
|
||||
* @return Promise a new resolved promise with value of the executed callback (onFulfilled / onRejected)
|
||||
*/
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null);
|
||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null);
|
||||
|
||||
/**
|
||||
* Returns the state of the promise, one of PENDING, FULFILLED or REJECTED.
|
||||
@@ -65,9 +61,9 @@ interface Promise
|
||||
*
|
||||
* @param bool $unwrap Whether to return resolved value / throw reason or not
|
||||
*
|
||||
* @return T Resolved value, null if $unwrap is set to false
|
||||
* @return ($unwrap is true ? mixed : null) Resolved value, null if $unwrap is set to false
|
||||
*
|
||||
* @throws \Exception the rejection reason if $unwrap is set to true and the request failed
|
||||
* @throws \Throwable the rejection reason if $unwrap is set to true and the request failed
|
||||
*/
|
||||
public function wait($unwrap = true);
|
||||
}
|
||||
|
||||
@@ -6,27 +6,20 @@ namespace Http\Promise;
|
||||
* A rejected promise.
|
||||
*
|
||||
* @author Joel Wurtz <joel.wurtz@gmail.com>
|
||||
*
|
||||
* @template-covariant T
|
||||
*
|
||||
* @implements Promise<T>
|
||||
*/
|
||||
final class RejectedPromise implements Promise
|
||||
{
|
||||
/**
|
||||
* @var \Exception
|
||||
* @var \Throwable
|
||||
*/
|
||||
private $exception;
|
||||
|
||||
public function __construct(\Exception $exception)
|
||||
public function __construct(\Throwable $exception)
|
||||
{
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||
{
|
||||
if (null === $onRejected) {
|
||||
return $this;
|
||||
@@ -39,21 +32,17 @@ final class RejectedPromise implements Promise
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getState()
|
||||
{
|
||||
return Promise::REJECTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wait($unwrap = true)
|
||||
{
|
||||
if ($unwrap) {
|
||||
throw $this->exception;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user