Skip to content

Commit 0b44a27

Browse files
committed
feature symfony#51100 [PsrHttpMessageBridge] Import the bridge into the monorepo (fabpot, dunglas, KorvinSzanto, xabbuh, aimeos, ahundiak, Danielss89, rougin, csunolgomez, Jérôme Parmentier, mtibben, Nyholm, ajgarlag, uphlewis, samnela, grachevko, nicolas-grekas, tinyroy, danizord, Daniel Degasperi, rbaarsma, Ekman, 4rthem, derrabus, mleczakm, iluuu1994, Tobion, chalasr, lemon-juice, franmomu, cidosx, erikn69, AurelienPillevesse)
This PR was merged into the 6.4 branch. Discussion ---------- [PsrHttpMessageBridge] Import the bridge into the monorepo | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | TODO ⚠️ Don't squash! I propose to import the `symfony/psr-http-message-bridge` package into the Symfony monorepo for further maintenance. Commits ------- e40dd66 [PsrHttpMessageBridge] Patch return types and fix CS 266c09f [PsrHttpMessageBridge] Import the bridge into the monorepo 0c0323a Add 'src/Symfony/Bridge/PsrHttpMessage/' from commit '581ca6067eb62640de5ff08ee1ba6850a0ee472e' 581ca60 Prepare release 2.3.1 45d0349 Fix CS 6410dda bug symfony#122 Don't rely on Request::getPayload() to populate the parsed body (nicolas-grekas) ef03b6d Don't rely on Request::getPayload() to populate the parsed body 3c62b81 minor symfony#120 Prepare release 2.3.0 (derrabus) 96acbfd Prepare release 2.3.0 7eedd34 feature symfony#119 Implement ValueResolverInterface (derrabus) 0b54b85 Implement ValueResolverInterface 6b2f5df feature symfony#117 Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests (AurelienPillevesse) 3a8caad Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests 18c9e82 minor symfony#118 Add native types where possible (derrabus) 4fd4323 Add native types where possible 28a732c minor symfony#115 Prepare the 2.2.0 release (derrabus) 7944831 cs fix 99ddcaa Prepare the 2.2.0 release 8a5748d feature symfony#113 Bump psr/http-message version (erikn69) ec83c1c Bump psr/http-message version 694016e feature symfony#114 Drop support for Symfony 4 (derrabus) b360b35 Drop support for Symfony 4 998d8d2 minor symfony#111 Adjustments for PHP CS Fixer 3 (derrabus) 5fa5f62 Adjustments for PHP CS Fixer 3 a125b93 minor symfony#110 Add PHP 8.2 to CI (derrabus) 4592df2 Add PHP 8.2 to CI 4617ac3 bug symfony#109 perf: ensure timely flush stream buffers (cidosx) 8c8a75b perf: ensure timely flush stream buffers d444f85 Update changelog 155a7ae bug symfony#107 Ignore invalid HTTP headers when creating PSR7 objects (nicolas-grekas) 9a78a16 Ignore invalid HTTP headers when creating PSR7 objects bdb2871 minor symfony#104 Add missing .gitattributes (franmomu) 808561a Add missing .gitattributes 316f5cb bug symfony#103 Fix for wrong type passed to moveTo() (lemon-juice) 7f3b5c1 Fix for wrong type passed to moveTo() 22b37c8 minor symfony#101 Release v2.1.2 (chalasr) c382d76 Release v2.1.2 c81476c feature symfony#100 Allow Symfony 6 (chalasr) c7a0be3 Allow Symfony 6 df83a38 minor symfony#98 Add PHP 8.1 to CI (derrabus) b2bd334 Add PHP 8.1 to CI 824711c minor symfony#99 Add return types to fixtures (derrabus) f8f70fa Add return types to fixtures d558dcd minor symfony#97 Inline $tmpDir (derrabus) d152649 Inline $tmpDir f12a9e6 minor symfony#96 Run PHPUnit on GitHub Actions (derrabus) ab64c69 Run PHPUnit on GitHub Actions c901299 bug symfony#95 Allow `psr/log` 2 and 3 (derrabus) 8e13ae4 Allow psr/log 2 and 3 26068fa Minor cleanups 87fabb9 Fix copyright year 3d9241f minor symfony#92 remove link to sensio extra bundle which removed psr7 support (Tobion) 7078739 remove link to sensio extra bundle which removed psr7 support 81db2d4 feature symfony#89 PSR HTTP message converters for controllers (derrabus) aa26e61 PSR HTTP message converters for controllers e62b239 minor symfony#91 Fix CS (derrabus) 2bead22 Fix CS 488df9b minor symfony#90 Fix CI failures with Xdebug 3 and test on PHP 7.4/8.0 as well (derrabus) a6697fd Fix CI failures with Xdebug 3 and test on PHP 7.4/8.0 as well c62f7d0 Update branch-alias 51a21cb Update changelog a20fff9 bug symfony#87 Fix populating server params from URI in HttpFoundationFactory (nicolas-grekas) 4933e04 bug symfony#86 Create cookies as raw in HttpFoundationFactory (nicolas-grekas) 66095a5 Fix populating server params from URI in HttpFoundationFactory 42cca49 Create cookies as raw in HttpFoundationFactory cffb3a8 bug symfony#85 Fix BinaryFileResponse with range to psr response conversion (iluuu1994) 5d5932d Fix BinaryFileResponse with range to psr response conversion e44f249 bug symfony#81 Don't normalize query string in PsrHttpFactory (nicolas-grekas) bc25829 Don't normalize query string in PsrHttpFactory df735ec bug symfony#78 Fix populating default port and headers in HttpFoundationFactory (mleczakm) 4f30401 Fix populating default port and headers in HttpFoundationFactory 1309b64 bug symfony#77 fix conversion for https requests (4rthem) e86de3f minor symfony#79 Allow installation on php 8 (derrabus) 9243f93 Allow installation on php 8. d336c73 fix conversion for https requests 126903c Fix format of CHANGELOG.md ce709cd feature symfony#75 Remove deprecated code (fabpot) dfc5238 Remove deprecated code 9d3e80d bug symfony#72 Use adapter for UploadedFile objects (nicolas-grekas) a4f9f6d Use adapter for UploadedFile objects ec7892b Fix CHANGELOG, bump branch-alias 7ab4fe4 minor symfony#70 Updated CHANGELOG (rbaarsma) 9ad4bcc Updated CHANGELOG c4c904a minor symfony#71 Cleanup after bump to Symfony v4.4 (nicolas-grekas) e9a9557 Cleanup after bump to Symfony v4.4 3d10a6c feature symfony#66 Add support for streamed Symfony request (Ekman) df26630 Add support for streamed Symfony request 5aa8ca9 bug symfony#69 Allow Symfony 5.0 (rbaarsma) 1158149 Allow Symfony 5.0 81ae86d Merge branch '1.1' a33352a bug symfony#64 Fixed createResponse (ddegasperi) 7a4b449 minor symfony#65 Fix tests (ajgarlag) 19905b0 Fix tests 580de38 Fixed createResponse 9ab9d71 minor symfony#63 Added links to documentation (Nyholm) 59b9406 Added links to documentation c1cb51c feature symfony#50 Add support for streamed response (danizord) 4133c7a bug symfony#48 Convert Request/Response multiple times (Nyholm) 8564bf7 Convert Request/Response multiple times 7cc1605 Add support for streamed response aebc14b feature symfony#62 bump to PHP 7.1 (nicolas-grekas) 8e10923 bump to PHP 7.1 5e5e0c3 Revert "Undeprecate DiactorosFactory for 1.1" 921f866 Undeprecate DiactorosFactory for 1.1 8592ca3 bug symfony#61 removed 'Set-Cookie' from header when it is already converted to a Symfony header cookie (tinyroy) dd1111e removed 'Set-Cookie' from header when it is already converted to a Symfony header cookie ba672d8 bump branch-alias 5f9a032 typo f2c48c5 fix tests 3a52e44 bug symfony#59 Fix SameSite attribute conversion from PSR7 to HttpFoundation (ajgarlag) 5ee1f8f Fix SameSite attribute conversion from PSR7 to HttpFoundation f6d7d3a bug symfony#58 [Bugfix] Typo header set-sookie (grachevko) 16eb6e1 minor symfony#57 Excluded tests from classmap (samnela) 36a8065 Deprecate DiactorosFactory, use nyholm/psr7 for tests 5076934 bug symfony#54 Fix symfony#51 (compatability issue with zendframework/zend-diactoros ^2.0) (uphlewis) 757ea81 [Bugfix] Typo header set-sookie 25f9c3a Excluded tests from classmap 8ff61e5 Fix compatability issue with "zendframework/zend-diactoros": "^2.0." (symfony#51) 53c15a6 updated CHANGELOG c821241 bumped version to 1.1 f26d01f minor symfony#47 Updated changelog (Nyholm) c2282e3 Updated changelog eddd6c8 feature symfony#43 Create PSR-7 messages using PSR-17 factories (ajgarlag) dd81b4b Create PSR-7 messages using PSR-17 factories f11f173 feature symfony#45 Fixed broken build (Nyholm) 8780dd3 Fixed broken build c2b7579 bug symfony#30 Fix the request target in PSR7 Request (mtibben) 94fcfa5 Fix the request target in PSR7 Request 64640ee minor symfony#38 Run PHP 5.3 tests on Precise (Lctrs) 64c0cb0 Run PHP 5.3 tests on Precise b209840 minor symfony#32 Allow Symfony 4 (dunglas) 97635f1 Allow Symfony 4 147a238 minor symfony#31 test suite compatibility with PHPUnit 6 (xabbuh) f5c46f0 test suite compatibility with PHPUnit 6 66085f2 preparing 1.0 release 533d3e4 added a CHANGELOG for 1.0 14269f9 bug symfony#28 Fix REQUEST_METHOD on symfony request (csunol) 98ab85a Fix REQUEST_METHOD on symfony request 29be4f8 updated LICENCE year d2db47c removed obsolete CHANGELOG file 1c30b17 bug symfony#22 Fixes symfony#16 Symfony Request created without any URI (rougin) a59c572 Fixes symfony#16 Symfony Request created without any URI 7a5aa92 bug symfony#23 Fixes symfony#9 Bridge error when no file is selected (ahundiak, Danielss89) a1a631a Update assert error message e5d62e6 Fixes based on code-review 101b608 Handles null file in createrequest bridge. d16c63c bug symfony#18 Allow multiple calls to Request::getContent() (aimeos) 9624b8b Allow multiple calls to Request::getContent() 9c747c4 Merge pull request symfony#19 from xabbuh/travis-config a388c43 update Travis CI configuration ac5cd86 minor symfony#14 Remove use of deprecated 'deep' parameter in tests (KorvinSzanto) 305c0fe Remove use of deprecated 'deep' parameter 3664dc0 minor symfony#7 Test Diactoros Factory with PHP 5.4 (dunglas) bab1530 Test Diactoros Factory with PHP 5.4 d7660b8 Suggest psr/http-message-implementation dc7e308 removed the branch alias for now as we are pre 1.0 3f8977e feature #1 Initial support (dunglas) ca41146 Initial support 01b110b added the initial set of files
2 parents bfb5963 + e40dd66 commit 0b44a27

30 files changed

+2778
-0
lines changed

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"psr/clock": "^1.0",
4545
"psr/container": "^1.1|^2.0",
4646
"psr/event-dispatcher": "^1.0",
47+
"psr/http-message": "^1.0|^2.0",
4748
"psr/link": "^1.1|^2.0",
4849
"psr/log": "^1|^2|^3",
4950
"symfony/contracts": "^2.5|^3.0",
@@ -94,6 +95,7 @@
9495
"symfony/property-access": "self.version",
9596
"symfony/property-info": "self.version",
9697
"symfony/proxy-manager-bridge": "self.version",
98+
"symfony/psr-http-message-bridge": "self.version",
9799
"symfony/rate-limiter": "self.version",
98100
"symfony/remote-event": "self.version",
99101
"symfony/routing": "self.version",
@@ -182,6 +184,7 @@
182184
"Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/",
183185
"Symfony\\Bridge\\Monolog\\": "src/Symfony/Bridge/Monolog/",
184186
"Symfony\\Bridge\\ProxyManager\\": "src/Symfony/Bridge/ProxyManager/",
187+
"Symfony\\Bridge\\PsrHttpMessage\\": "src/Symfony/Bridge/PsrHttpMessage/",
185188
"Symfony\\Bridge\\Twig\\": "src/Symfony/Bridge/Twig/",
186189
"Symfony\\Bundle\\": "src/Symfony/Bundle/",
187190
"Symfony\\Component\\": "src/Symfony/Component/"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
4+
/Tests/Fixtures/App/var
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
13+
14+
use Psr\Http\Message\MessageInterface;
15+
use Psr\Http\Message\RequestInterface;
16+
use Psr\Http\Message\ServerRequestInterface;
17+
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
18+
use Symfony\Component\HttpFoundation\Request;
19+
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
20+
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface as BaseValueResolverInterface;
21+
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
22+
23+
/**
24+
* Injects the RequestInterface, MessageInterface or ServerRequestInterface when requested.
25+
*
26+
* @author Iltar van der Berg <kjarli@gmail.com>
27+
* @author Alexander M. Turek <me@derrabus.de>
28+
*/
29+
final class PsrServerRequestResolver implements ArgumentValueResolverInterface, ValueResolverInterface
30+
{
31+
private const SUPPORTED_TYPES = [
32+
ServerRequestInterface::class => true,
33+
RequestInterface::class => true,
34+
MessageInterface::class => true,
35+
];
36+
37+
private $httpMessageFactory;
38+
39+
public function __construct(HttpMessageFactoryInterface $httpMessageFactory)
40+
{
41+
$this->httpMessageFactory = $httpMessageFactory;
42+
}
43+
44+
public function supports(Request $request, ArgumentMetadata $argument): bool
45+
{
46+
if ($this instanceof BaseValueResolverInterface) {
47+
trigger_deprecation('symfony/psr-http-message-bridge', '2.3', 'Method "%s" is deprecated, call "resolve()" without calling "supports()" first.', __METHOD__);
48+
}
49+
50+
return self::SUPPORTED_TYPES[$argument->getType()] ?? false;
51+
}
52+
53+
public function resolve(Request $request, ArgumentMetadata $argument): \Traversable
54+
{
55+
if (!isset(self::SUPPORTED_TYPES[$argument->getType()])) {
56+
return;
57+
}
58+
59+
yield $this->httpMessageFactory->createRequest($request);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
13+
14+
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface as BaseValueResolverInterface;
15+
16+
if (interface_exists(BaseValueResolverInterface::class)) {
17+
/** @internal */
18+
interface ValueResolverInterface extends BaseValueResolverInterface
19+
{
20+
}
21+
} else {
22+
/** @internal */
23+
interface ValueResolverInterface
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
CHANGELOG
2+
=========
3+
4+
6.4
5+
---
6+
7+
* Import the bridge into the Symfony monorepo and synchronize releases
8+
9+
2.3.1
10+
-----
11+
12+
* Don't rely on `Request::getPayload()` to populate the parsed body
13+
14+
2.3.0
15+
-----
16+
17+
* Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests
18+
* Implement `ValueResolverInterface` introduced with Symfony 6.2
19+
20+
2.2.0
21+
-----
22+
23+
* Drop support for Symfony 4
24+
* Bump minimum version of PHP to 7.2
25+
* Support version 2 of the psr/http-message contracts
26+
27+
2.1.3
28+
-----
29+
30+
* Ignore invalid HTTP headers when creating PSR7 objects
31+
* Fix for wrong type passed to `moveTo()`
32+
33+
2.1.2
34+
-----
35+
36+
* Allow Symfony 6
37+
38+
2.1.0
39+
-----
40+
41+
* Added a `PsrResponseListener` to automatically convert PSR-7 responses returned by controllers
42+
* Added a `PsrServerRequestResolver` that allows injecting PSR-7 request objects into controllers
43+
44+
2.0.2
45+
-----
46+
47+
* Fix populating server params from URI in HttpFoundationFactory
48+
* Create cookies as raw in HttpFoundationFactory
49+
* Fix BinaryFileResponse with Content-Range PsrHttpFactory
50+
51+
2.0.1
52+
-----
53+
54+
* Don't normalize query string in PsrHttpFactory
55+
* Fix conversion for HTTPS requests
56+
* Fix populating default port and headers in HttpFoundationFactory
57+
58+
2.0.0
59+
-----
60+
61+
* Remove DiactorosFactory
62+
63+
1.3.0
64+
-----
65+
66+
* Added support for streamed requests
67+
* Added support for Symfony 5.0+
68+
* Fixed bridging UploadedFile objects
69+
* Bumped minimum version of Symfony to 4.4
70+
71+
1.2.0
72+
-----
73+
74+
* Added new documentation links
75+
* Bumped minimum version of PHP to 7.1
76+
* Added support for streamed responses
77+
78+
1.1.2
79+
-----
80+
81+
* Fixed createResponse
82+
83+
1.1.1
84+
-----
85+
86+
* Deprecated DiactorosFactory, use PsrHttpFactory instead
87+
* Removed triggering of deprecation
88+
89+
1.1.0
90+
-----
91+
92+
* Added support for creating PSR-7 messages using PSR-17 factories
93+
94+
1.0.2
95+
-----
96+
97+
* Fixed request target in PSR7 Request (mtibben)
98+
99+
1.0.1
100+
-----
101+
102+
* Added support for Symfony 4 (dunglas)
103+
104+
1.0.0
105+
-----
106+
107+
* Initial release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PsrHttpMessage\EventListener;
13+
14+
use Psr\Http\Message\ResponseInterface;
15+
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
16+
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
17+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18+
use Symfony\Component\HttpKernel\Event\ViewEvent;
19+
use Symfony\Component\HttpKernel\KernelEvents;
20+
21+
/**
22+
* Converts PSR-7 Response to HttpFoundation Response using the bridge.
23+
*
24+
* @author Kévin Dunglas <dunglas@gmail.com>
25+
* @author Alexander M. Turek <me@derrabus.de>
26+
*/
27+
final class PsrResponseListener implements EventSubscriberInterface
28+
{
29+
private $httpFoundationFactory;
30+
31+
public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory = null)
32+
{
33+
$this->httpFoundationFactory = $httpFoundationFactory ?? new HttpFoundationFactory();
34+
}
35+
36+
/**
37+
* Do the conversion if applicable and update the response of the event.
38+
*/
39+
public function onKernelView(ViewEvent $event): void
40+
{
41+
$controllerResult = $event->getControllerResult();
42+
43+
if (!$controllerResult instanceof ResponseInterface) {
44+
return;
45+
}
46+
47+
$event->setResponse($this->httpFoundationFactory->createResponse($controllerResult));
48+
}
49+
50+
public static function getSubscribedEvents(): array
51+
{
52+
return [
53+
KernelEvents::VIEW => 'onKernelView',
54+
];
55+
}
56+
}

0 commit comments

Comments
 (0)