This commit is contained in:
2026-02-02 15:18:51 +01:00
parent 7a26dd69a5
commit ae0ee002ec
170 changed files with 7446 additions and 1519 deletions

View File

@@ -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": {

View File

@@ -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);

View File

@@ -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
{
}

View File

@@ -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);
}

View File

@@ -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.
*/

View File

@@ -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();

View File

@@ -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);

View File

@@ -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.
*