8000 Add 'src/Symfony/Bridge/PsrHttpMessage/' from commit '581ca6067eb6264… · symfony/symfony@0c0323a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c0323a

Browse files
committed
Add 'src/Symfony/Bridge/PsrHttpMessage/' from commit '581ca6067eb62640de5ff08ee1ba6850a0ee472e'
git-subtree-dir: src/Symfony/Bridge/PsrHttpMessage git-subtree-mainline: 510e51f git-subtree-split: 581ca60
2 parents 510e51f + 581ca60 commit 0c0323a

31 files changed

+2872
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitattributes export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.php_cs.dist export-ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
test:
9+
name: 'Test ${{ matrix.deps }} on PHP ${{ matrix.php }}'
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
16+
include:
17+
- php: '7.4'
18+
deps: lowest
19+
deprecations: max[self]=0
20+
- php: '8.1'
21+
deps: highest
22+
deprecations: max[indirect]=5
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: '${{ matrix.php }}'
32+
coverage: none
33+
34+
- name: Configure composer
35+
if: "${{ matrix.deps == 'highest' }}"
36+
run: composer config minimum-stability dev
37+
38+
- name: Composer install
39+
uses: ramsey/composer-install@v1
40+
with:
41+
dependency-versions: '${{ matrix.deps }}'
42+
43+
- name: Install PHPUnit
44+
run: vendor/bin/simple-phpunit install
45+
46+
- name: Run tests
47+
run: vendor/bin/simple-phpunit
48+
env:
49+
SYMFONY_DEPRECATIONS_HELPER: '${{ matrix.deprecations }}'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
4+
.php-cs-fixer.cache
5+
.php-cs-fixer.php
6+
.phpunit.result.cache
7+
/Tests/Fixtures/App/var
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
return (new PhpCsFixer\Config())
4+
->setRules([
5+
'@Symfony' => true,
6+
'@Symfony:risky' => true,
7+
'@PHPUnit48Migration:risky' => true,
8+
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
9+
'array_syntax' => ['syntax' => 'short'],
10+
'fopen_flags' => false,
11+
'ordered_imports' => true,
12+
'protected_to_private' => false,
13+
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
14+
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
15+
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
16+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
17+
])
18+
->setRiskyAllowed(true)
19+
->setFinder(
20+
(new PhpCsFixer\Finder())
21+
->in(__DIR__)
22+
->exclude('vendor')
23+
->name('*.php')
24+
)
25+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+< F987 /span>
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+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function supports(Request $request, ArgumentMetadata $argument): bool
48+
{
49+
if ($this instanceof BaseValueResolverInterface) {
50+
trigger_deprecation('symfony/psr-http-message-bridge', '2.3', 'Method "%s" is deprecated, call "resolve()" without calling "supports()" first.', __METHOD__);
51+
}
52+
53+
return self::SUPPORTED_TYPES[$argument->getType()] ?? false;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
public function resolve(Request $request, ArgumentMetadata $argument): \Traversable
60+
{
61+
if (!isset(self::SUPPORTED_TYPES[$argument->getType()])) {
62+
return;
63+
}
64+
65+
yield $this->httpMessageFactory->createRequest($request);
66+
}
67+
}
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,85 @@
1+
CHANGELOG
2+
=========
3+
4+
# 2.3.1 (2023-07-26)
5+
6+
* Don't rely on `Request::getPayload()` to populate the parsed body
7+
8+
# 2.3.0 (2023-07-25)
9+
10+
* Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests
11+
* Implement `ValueResolverInterface` introduced with Symfony 6.2
12+
13+
# 2.2.0 (2023-04-21)
14+
15+
* Drop support for Symfony 4
16+
* Bump minimum version of PHP to 7.2
17+
* Support version 2 of the psr/http-message contracts
18+
19+
# 2.1.3 (2022-09-05)
20+
21+
* Ignore invalid HTTP headers when creating PSR7 objects
22+
* Fix for wrong type passed to `moveTo()`
23+
24+
# 2.1.2 (2021-11-05)
25+
26+
* Allow Symfony 6
27+
28+
# 2.1.0 (2021-02-17)
29+
30+
* Added a `PsrResponseListener` to automatically convert PSR-7 responses returned by controllers
31+
* Added a `PsrServerRequestResolver` that allows injecting PSR-7 request objects into controllers
32+
33+
# 2.0.2 (2020-09-29)
34+
35+
* Fix populating server params from URI in HttpFoundationFactory
36+
* Create cookies as raw in HttpFoundationFactory
37+
* Fix BinaryFileResponse with Content-Range PsrHttpFactory
38+
39+
# 2.0.1 (2020-06-25)
40+
41+
* Don't normalize query string in PsrHttpFactory
42+
* Fix conversion for HTTPS requests
43+
* Fix populating default port and headers in HttpFoundationFactory
44+
45+
# 2.0.0 (2020-01-02)
46+
47+
* Remove DiactorosFactory
48+
49+
# 1.3.0 (2019-11-25)
50+
51+
* Added support for streamed requests
52+
* Added support for Symfony 5.0+
53+
* Fixed bridging UploadedFile objects
54+
* Bumped minimum version of Symfony to 4.4
55+
56+
# 1.2.0 (2019-03-11)
57+
58+
* Added new documentation links
59+
* Bumped minimum version of PHP to 7.1
60+
* Added support for streamed responses
61+
62+
# 1.1.2 (2019-04-03)
63+
64+
* Fixed createResponse
65+
66+
# 1.1.1 (2019-03-11)
67+
68+
* Deprecated DiactorosFactory, use PsrHttpFactory instead
69+
* Removed triggering of deprecation
70+
71+
# 1.1.0 (2018-08-30)
72+
73+
* Added support for creating PSR-7 messages using PSR-17 factories
74+
75+
# 1.0.2 (2017-12-19)
76+
77+
* Fixed request target in PSR7 Request (mtibben)
78+
79+
# 1.0.1 (2017-12-04)
80+
81+
* Added support for Symfony 4 (dunglas)
82+
83+
# 1.0.0 (2016-09-14)
84+
85+
* Initial release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\PsrHttpMessage\EventListener;
4+
5+
use Psr\Http\Message\ResponseInterface;
6+
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
7+
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
8+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9+
use Symfony\Component\HttpKernel\Event\ViewEvent;
10+
use Symfony\Component\HttpKernel\KernelEvents;
11+
12+
/**
13+
* Converts PSR-7 Response to HttpFoundation Response using the bridge.
14+
*
15+
* @author Kévin Dunglas <dunglas@gmail.com>
16+
* @author Alexander M. Turek <me@derrabus.de>
17+
*/
18+
final class PsrResponseListener implements EventSubscriberInterface
19+
{
20+
private $httpFoundationFactory;
21+
22+
public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory = null)
23+
{
24+
$this->httpFoundationFactory = $httpFoundationFactory ?? new HttpFoundationFactory();
25+
}
26+
27+
/**
28+
* Do the conversion if applicable and update the response of the event.
29+
*/
30+
public function onKernelView(ViewEvent $event): void
31+
{
32+
$controllerResult = $event->getControllerResult();
33+
34+
if (!$controllerResult instanceof ResponseInterface) {
35+
return;
36+
}
37+
38+
$event->setResponse($this->httpFoundationFactory->createResponse($controllerResult));
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public static function getSubscribedEvents(): array
45+
{
46+
return [
47+
KernelEvents::VIEW => 'onKernelView',
48+
];
49+
}
50+
}

0 commit comments

Comments
 (0)
0