Skip to content

Commit 682827f

Browse files
[11.x] Support auto-discovery of PSR-17 implementations (#53711)
* auto-discovery of psr-17 http factory implementation * wip
1 parent ab7edea commit 682827f

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@
109109
"league/flysystem-read-only": "^3.25.1",
110110
"league/flysystem-sftp-v3": "^3.25.1",
111111
"mockery/mockery": "^1.6.10",
112-
"nyholm/psr7": "^1.2",
113112
"orchestra/testbench-core": "^9.6",
114113
"pda/pheanstalk": "^5.0.6",
114+
"php-http/discovery": "^1.15",
115115
"phpstan/phpstan": "^1.11.5",
116116
"phpunit/phpunit": "^10.5.35|^11.3.6",
117117
"predis/predis": "^2.3",
118118
"resend/resend-php": "^0.10.0",
119119
"symfony/cache": "^7.0.3",
120120
"symfony/http-client": "^7.0.3",
121-
"symfony/translation": "^7.0.3",
122-
"symfony/psr-http-message-bridge": "^7.0.3"
121+
"symfony/psr-http-message-bridge": "^7.0.3",
122+
"symfony/translation": "^7.0.3"
123123
},
124124
"conflict": {
125125
"mockery/mockery": "1.6.8",
@@ -184,8 +184,8 @@
184184
"league/flysystem-read-only": "Required to use read-only disks (^3.25.1)",
185185
"league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.25.1).",
186186
"mockery/mockery": "Required to use mocking (^1.6).",
187-
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
188187
"pda/pheanstalk": "Required to use the beanstalk queue driver (^5.0).",
188+
"php-http/discovery": "Required to use PSR-7 bridging features (^1.15).",
189189
"phpunit/phpunit": "Required to use assertions and run tests (^10.5|^11.0).",
190190
"predis/predis": "Required to use the predis connector (^2.3).",
191191
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
@@ -201,7 +201,8 @@
201201
"config": {
202202
"sort-packages": true,
203203
"allow-plugins": {
204-
"composer/package-versions-deprecated": true
204+
"composer/package-versions-deprecated": true,
205+
"php-http/discovery": false
205206
}
206207
},
207208
"minimum-stability": "stable",

src/Illuminate/Routing/RoutingServiceProvider.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
1010
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;
1111
use Illuminate\Support\ServiceProvider;
12-
use Nyholm\Psr7\Factory\Psr17Factory;
13-
use Nyholm\Psr7\Response as PsrResponse;
1412
use Psr\Http\Message\ResponseInterface;
1513
use Psr\Http\Message\ServerRequestInterface;
1614
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
15+
use Symfony\Component\HttpFoundation\Response;
1716

1817
class RoutingServiceProvider extends ServiceProvider
1918
{
@@ -134,10 +133,8 @@ protected function registerRedirector()
134133
protected function registerPsrRequest()
135134
{
136135
$this->app->bind(ServerRequestInterface::class, function ($app) {
137-
if (class_exists(Psr17Factory::class) && class_exists(PsrHttpFactory::class)) {
138-
$psr17Factory = new Psr17Factory;
139-
140-
return with((new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory))
136+
if (class_exists(PsrHttpFactory::class)) {
137+
return with((new PsrHttpFactory)
141138
->createRequest($illuminateRequest = $app->make('request')), function (ServerRequestInterface $request) use ($illuminateRequest) {
142139
if ($illuminateRequest->getContentTypeFormat() !== 'json' && $illuminateRequest->request->count() === 0) {
143140
return $request;
@@ -149,7 +146,7 @@ protected function registerPsrRequest()
149146
});
150147
}
151148

152-
throw new BindingResolutionException('Unable to resolve PSR request. Please install the symfony/psr-http-message-bridge and nyholm/psr7 packages.');
149+
throw new BindingResolutionException('Unable to resolve PSR request. Please install the "symfony/psr-http-message-bridge" package.');
153150
});
154151
}
155152

@@ -161,11 +158,11 @@ protected function registerPsrRequest()
161158
protected function registerPsrResponse()
162159
{
163160
$this->app->bind(ResponseInterface::class, function () {
164-
if (class_exists(PsrResponse::class)) {
165-
return new PsrResponse;
161+
if (class_exists(PsrHttpFactory::class)) {
162+
return (new PsrHttpFactory)->createResponse(new Response);
166163
}
167164

168-
throw new BindingResolutionException('Unable to resolve PSR response. Please install the nyholm/psr7 package.');
165+
throw new BindingResolutionException('Unable to resolve PSR response. Please install the "symfony/psr-http-message-bridge" package.');
169166
});
170167
}
171168

src/Illuminate/Routing/composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@
4141
},
4242
"suggest": {
4343
"illuminate/console": "Required to use the make commands (^11.0).",
44-
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
44+
"php-http/discovery": "Required to use PSR-7 bridging features (^1.15).",
4545
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^7.0)."
4646
},
4747
"config": {
48-
"sort-packages": true
48+
"sort-packages": true,
49+
"allow-plugins": {
50+
"php-http/discovery": false
51+
}
4952
},
5053
"minimum-stability": "dev"
5154
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Routing;
4+
5+
use Orchestra\Testbench\TestCase;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
9+
class RoutingServiceProviderTest extends TestCase
10+
{
11+
public function testResolvingPsrRequest()
12+
{
13+
$psrRequest = $this->app->make(ServerRequestInterface::class);
14+
15+
$this->assertInstanceOf(ServerRequestInterface::class, $psrRequest);
16+
}
17+
18+
public function testResolvingPsrResponse()
19+
{
20+
$psrResponse = $this->app->make(ResponseInterface::class);
21+
22+
$this->assertInstanceOf(ResponseInterface::class, $psrResponse);
23+
}
24+
}

0 commit comments

Comments
 (0)