From 8c9318d79226516943c02fd983d94770c17a562e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Jan 2021 11:28:38 +0100 Subject: [PATCH] Remove PSR-7 support --- CHANGELOG.md | 5 ++ composer.json | 4 +- src/DependencyInjection/Configuration.php | 7 --- .../SensioFrameworkExtraExtension.php | 9 --- src/EventListener/PsrResponseListener.php | 60 ------------------- .../Psr7ServerRequestResolver.php | 54 ----------------- src/Resources/config/psr7.xml | 36 ----------- src/Resources/doc/index.rst | 44 -------------- .../EventListener/PsrResponseListenerTest.php | 53 ---------------- .../ActionArgumentsBundle.php | 18 ------ .../Controller/ActionArgumentsController.php | 40 ------------- .../NullableArgumentsController.php | 47 --------------- tests/Fixtures/TestKernel.php | 1 - tests/Fixtures/config/config.yml | 3 - .../Fixtures/config/nullable_type/routing.yml | 4 -- tests/Fixtures/config/routing.yml | 4 -- tests/Functional/NullableAnnotationTest.php | 33 ---------- tests/Functional/Psr7RequestTest.php | 34 ----------- 18 files changed, 6 insertions(+), 450 deletions(-) delete mode 100644 src/EventListener/PsrResponseListener.php delete mode 100644 src/Request/ArgumentValueResolver/Psr7ServerRequestResolver.php delete mode 100644 src/Resources/config/psr7.xml delete mode 100644 tests/EventListener/PsrResponseListenerTest.php delete mode 100644 tests/Fixtures/ActionArgumentsBundle/ActionArgumentsBundle.php delete mode 100644 tests/Fixtures/ActionArgumentsBundle/Controller/ActionArgumentsController.php delete mode 100644 tests/Fixtures/ActionArgumentsBundle/Controller/NullableArgumentsController.php delete mode 100644 tests/Functional/NullableAnnotationTest.php delete mode 100644 tests/Functional/Psr7RequestTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index a59c2480..e06544dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.0 +--- + + * Remove PSR-7 support + 5.6 --- diff --git a/composer.json b/composer.json index 53e99560..1b11b6f5 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "doctrine/dbal": "^2.10|^3.0", "doctrine/doctrine-bundle": "^1.11|^2.0", "doctrine/orm": "^2.5", - "nyholm/psr7": "^1.1", "symfony/browser-kit": "^4.4|^5.0", "symfony/doctrine-bridge": "^4.4|^5.0", "symfony/dom-crawler": "^4.4|^5.0", @@ -31,7 +30,6 @@ "symfony/monolog-bundle": "^3.2", "symfony/monolog-bridge": "^4.0|^5.0", "symfony/phpunit-bridge": "^4.4.9|^5.0.9", - "symfony/psr-http-message-bridge": "^1.1", "symfony/security-bundle": "^4.4|^5.0", "symfony/twig-bundle": "^4.4|^5.0", "symfony/yaml": "^4.4|^5.0", @@ -58,7 +56,7 @@ }, "extra": { "branch-alias": { - "dev-master": "5.6.x-dev" + "dev-master": "6.0.x-dev" } } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e252d45c..577edc46 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,7 +11,6 @@ namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection; -use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\NodeInterface; @@ -74,12 +73,6 @@ public function getConfigTreeBuilder() ->scalarNode('expression_language')->defaultValue('sensio_framework_extra.security.expression_language.default')->end() ->end() ->end() - ->arrayNode('psr_message') - ->addDefaultsIfNotSet() - ->children() - ->booleanNode('enabled')->defaultValue(interface_exists(HttpFoundationFactoryInterface::class))->end() - ->end() - ->end() ->arrayNode('templating') ->fixXmlConfig('controller_pattern') ->children() diff --git a/src/DependencyInjection/SensioFrameworkExtraExtension.php b/src/DependencyInjection/SensioFrameworkExtraExtension.php index 39ebe556..f949364c 100644 --- a/src/DependencyInjection/SensioFrameworkExtraExtension.php +++ b/src/DependencyInjection/SensioFrameworkExtraExtension.php @@ -11,7 +11,6 @@ namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection; -use Psr\Http\Message\StreamFactoryInterface; use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\ClassExistenceResource; @@ -103,14 +102,6 @@ public function load(array $configs, ContainerBuilder $container) ->addArgument($config['templating']['controller_patterns']); } - if ($config['psr_message']['enabled']) { - $loader->load('psr7.xml'); - - if (!interface_exists(StreamFactoryInterface::class)) { - $definitionsToRemove[] = 'sensio_framework_extra.psr7.argument_value_resolver.server_request'; - } - } - foreach ($definitionsToRemove as $definition) { $container->removeDefinition($definition); } diff --git a/src/EventListener/PsrResponseListener.php b/src/EventListener/PsrResponseListener.php deleted file mode 100644 index bcdb69ad..00000000 --- a/src/EventListener/PsrResponseListener.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sensio\Bundle\FrameworkExtraBundle\EventListener; - -use Psr\Http\Message\ResponseInterface; -use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\KernelEvent; -use Symfony\Component\HttpKernel\KernelEvents; - -/** - * Converts PSR-7 Response to HttpFoundation Response using the bridge. - * - * @author Kévin Dunglas - */ -class PsrResponseListener implements EventSubscriberInterface -{ - /** - * @var HttpFoundationFactoryInterface - */ - private $httpFoundationFactory; - - public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory) - { - $this->httpFoundationFactory = $httpFoundationFactory; - } - - /** - * Do the conversion if applicable and update the response of the event. - */ - public function onKernelView(KernelEvent $event) - { - $controllerResult = $event->getControllerResult(); - - if (!$controllerResult instanceof ResponseInterface) { - return; - } - - $event->setResponse($this->httpFoundationFactory->createResponse($controllerResult)); - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - KernelEvents::VIEW => 'onKernelView', - ]; - } -} diff --git a/src/Request/ArgumentValueResolver/Psr7ServerRequestResolver.php b/src/Request/ArgumentValueResolver/Psr7ServerRequestResolver.php deleted file mode 100644 index 01e03432..00000000 --- a/src/Request/ArgumentValueResolver/Psr7ServerRequestResolver.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sensio\Bundle\FrameworkExtraBundle\Request\ArgumentValueResolver; - -use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; -use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; - -/** - * Injects the RequestInterface, MessageInterface or ServerRequestInterface when requested. - * - * @author Iltar van der Berg - */ -final class Psr7ServerRequestResolver implements ArgumentValueResolverInterface -{ - private static $supportedTypes = [ - 'Psr\Http\Message\ServerRequestInterface' => true, - 'Psr\Http\Message\RequestInterface' => true, - 'Psr\Http\Message\MessageInterface' => true, - ]; - - private $httpMessageFactory; - - public function __construct(HttpMessageFactoryInterface $httpMessageFactory) - { - $this->httpMessageFactory = $httpMessageFactory; - } - - /** - * {@inheritdoc} - */ - public function supports(Request $request, ArgumentMetadata $argument) - { - return isset(self::$supportedTypes[$argument->getType()]); - } - - /** - * {@inheritdoc} - */ - public function resolve(Request $request, ArgumentMetadata $argument) - { - yield $this->httpMessageFactory->createRequest($request); - } -} diff --git a/src/Resources/config/psr7.xml b/src/Resources/config/psr7.xml deleted file mode 100644 index 7fdf5418..00000000 --- a/src/Resources/config/psr7.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/doc/index.rst b/src/Resources/doc/index.rst index 85f354de..5ef7be58 100644 --- a/src/Resources/doc/index.rst +++ b/src/Resources/doc/index.rst @@ -35,7 +35,6 @@ The default configuration is as follow: view: { annotations: true } cache: { annotations: true } security: { annotations: true } - psr_message: { enabled: false } # Defaults to true if the PSR-7 bridge is installed .. code-block:: xml @@ -47,7 +46,6 @@ The default configuration is as follow: - .. code-block:: php @@ -59,7 +57,6 @@ The default configuration is as follow: 'view' => array('annotations' => true), 'cache' => array('annotations' => true), 'security' => array('annotations' => true), - 'psr_message' => array('enabled' => false), // Defaults to true if the PSR-7 bridge is installed )); You can disable some annotations and conventions by defining one or more @@ -162,45 +159,4 @@ example: resource: "@AnnotRoutingBundle/Controller" type: annotation -PSR-7 support -------------- - -SensioFrameworkExtraBundle provides support for HTTP messages interfaces defined -in `PSR-7`_. It allows to inject instances of ``Psr\Http\Message\ServerRequestInterface`` -and to return instances of ``Psr\Http\Message\ResponseInterface`` in controllers. - -To enable this feature, `the HttpFoundation to PSR-7 bridge`_ and `autowiring -aliases for PSR-17`_ must be installed: - -.. code-block:: bash - - $ composer require symfony/psr-http-message-bridge nyholm/psr7 - -Then, PSR-7 messages can be used directly in controllers like in the following code -snippet:: - - namespace AppBundle\Controller; - - use Psr\Http\Message\ResponseFactoryInterface; - use Psr\Http\Message\ServerRequestInterface; - - class DefaultController - { - public function index(ServerRequestInterface $request, ResponseFactoryInterface $responseFactory) - { - // Interact with the PSR-7 request - - $response = $responseFactory->createResponse(); - // Interact with the PSR-7 response - - return $response; - } - } - -Note that internally, Symfony always use :class:`Symfony\\Component\\HttpFoundation\\Request` -and :class:`Symfony\\Component\\HttpFoundation\\Response` instances. - .. _`SensioFrameworkExtraBundle`: https://github.com/sensiolabs/SensioFrameworkExtraBundle -.. _`PSR-7`: http://www.php-fig.org/psr/psr-7/ -.. _`the HttpFoundation to PSR-7 bridge`: https://github.com/symfony/psr-http-message-bridge -.. _`autowiring aliases for PSR-17`: https://github.com/symfony/recipes/blob/master/nyholm/psr7/1.0/config/packages/nyholm_psr7.yaml diff --git a/tests/EventListener/PsrResponseListenerTest.php b/tests/EventListener/PsrResponseListenerTest.php deleted file mode 100644 index 86a170dc..00000000 --- a/tests/EventListener/PsrResponseListenerTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sensio\Bundle\FrameworkExtraBundle\Tests\EventListener; - -use Sensio\Bundle\FrameworkExtraBundle\EventListener\PsrResponseListener; -use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; -use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Response; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\ViewEvent; -use Symfony\Component\HttpKernel\HttpKernelInterface; - -/** - * @author Kévin Dunglas - * @requires PHP 5.4 - */ -class PsrResponseListenerTest extends \PHPUnit\Framework\TestCase -{ - public function testConvertsControllerResult() - { - $listener = new PsrResponseListener(new HttpFoundationFactory()); - $event = $this->createEventMock(new Response()); - $listener->onKernelView($event); - $this->assertTrue($event->hasResponse()); - } - - public function testDoesNotConvertControllerResult() - { - $listener = new PsrResponseListener(new HttpFoundationFactory()); - $event = $this->createEventMock([]); - - $listener->onKernelView($event); - $this->assertFalse($event->hasResponse()); - - $event = $this->createEventMock(null); - - $listener->onKernelView($event); - $this->assertFalse($event->hasResponse()); - } - - private function createEventMock($controllerResult) - { - return new ViewEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST, $controllerResult); - } -} diff --git a/tests/Fixtures/ActionArgumentsBundle/ActionArgumentsBundle.php b/tests/Fixtures/ActionArgumentsBundle/ActionArgumentsBundle.php deleted file mode 100644 index a31f9b54..00000000 --- a/tests/Fixtures/ActionArgumentsBundle/ActionArgumentsBundle.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Tests\Fixtures\ActionArgumentsBundle; - -use Symfony\Component\HttpKernel\Bundle\Bundle; - -class ActionArgumentsBundle extends Bundle -{ -} diff --git a/tests/Fixtures/ActionArgumentsBundle/Controller/ActionArgumentsController.php b/tests/Fixtures/ActionArgumentsBundle/Controller/ActionArgumentsController.php deleted file mode 100644 index a945e908..00000000 --- a/tests/Fixtures/ActionArgumentsBundle/Controller/ActionArgumentsController.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Tests\Fixtures\ActionArgumentsBundle\Controller; - -use Psr\Http\Message\MessageInterface; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ServerRequestInterface; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; - -/** - * @Route("/action-arguments") - */ -class ActionArgumentsController -{ - /** - * @Route("/invoke/") - */ - public function __invoke(RequestInterface $request, MessageInterface $message, ServerRequestInterface $serverRequest) - { - return new Response('ok'); - } - - /** - * @Route("/normal/") - */ - public function normalAction(RequestInterface $request, MessageInterface $message, ServerRequestInterface $serverRequest) - { - return new Response('ok'); - } -} diff --git a/tests/Fixtures/ActionArgumentsBundle/Controller/NullableArgumentsController.php b/tests/Fixtures/ActionArgumentsBundle/Controller/NullableArgumentsController.php deleted file mode 100644 index e7f73c87..00000000 --- a/tests/Fixtures/ActionArgumentsBundle/Controller/NullableArgumentsController.php +++ /dev/null @@ -1,47 +0,0 @@ -ok'); - } - - /** - * @Route("/with-default") - */ - public function withDefaultAction(string $d = null) - { - return new Response(null === $d ? 'yes' : 'no'); - } - - /** - * @Route("/without-default") - */ - public function withoutDefaultAction(string $d) - { - return new Response(null === $d ? 'yes' : 'no'); - } - - /** - * @Route("/nullable") - */ - public function nullableAction(?string $d) - { - return new Response(null === $d ? 'yes' : 'no'); - } -} diff --git a/tests/Fixtures/TestKernel.php b/tests/Fixtures/TestKernel.php index acaa9d0a..a32f6005 100644 --- a/tests/Fixtures/TestKernel.php +++ b/tests/Fixtures/TestKernel.php @@ -29,7 +29,6 @@ public function registerBundles() new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new \Symfony\Bundle\SecurityBundle\SecurityBundle(), new \Tests\Fixtures\FooBundle\FooBundle(), - new \Tests\Fixtures\ActionArgumentsBundle\ActionArgumentsBundle(), ]; } diff --git a/tests/Fixtures/config/config.yml b/tests/Fixtures/config/config.yml index b55a7af4..9bd3fe06 100644 --- a/tests/Fixtures/config/config.yml +++ b/tests/Fixtures/config/config.yml @@ -28,9 +28,6 @@ services: Tests\Fixtures\FooBundle\Controller\SimpleController: public: true - Tests\Fixtures\ActionArgumentsBundle\Controller\ActionArgumentsController: - public: true - Tests\Fixtures\FooBundle\Security\IsGrantedVoter: public: false tags: diff --git a/tests/Fixtures/config/nullable_type/routing.yml b/tests/Fixtures/config/nullable_type/routing.yml index 683144c2..aed9e271 100644 --- a/tests/Fixtures/config/nullable_type/routing.yml +++ b/tests/Fixtures/config/nullable_type/routing.yml @@ -7,7 +7,3 @@ foo_bundle_with_variadics: defaults: _controller: '\Tests\Fixtures\FooBundle\ControllerWithVariadics\IsGrantedControllerWithVariadics::some4Action' params: ["foo", "bar"] - -action_arguments_bundle: - resource: "@ActionArgumentsBundle/Controller" - type: annotation diff --git a/tests/Fixtures/config/routing.yml b/tests/Fixtures/config/routing.yml index 7941e6dd..aed9e271 100644 --- a/tests/Fixtures/config/routing.yml +++ b/tests/Fixtures/config/routing.yml @@ -7,7 +7,3 @@ foo_bundle_with_variadics: defaults: _controller: '\Tests\Fixtures\FooBundle\ControllerWithVariadics\IsGrantedControllerWithVariadics::some4Action' params: ["foo", "bar"] - -action_arguments_bundle: - resource: "@ActionArgumentsBundle/Controller/ActionArgumentsController.php" - type: annotation diff --git a/tests/Functional/NullableAnnotationTest.php b/tests/Functional/NullableAnnotationTest.php deleted file mode 100644 index 7d2f91c3..00000000 --- a/tests/Functional/NullableAnnotationTest.php +++ /dev/null @@ -1,33 +0,0 @@ -request('GET', '/nullable-arguments/without-default'); - - $this->assertSame(500, $client->getResponse()->getStatusCode()); - } - - public function testArgumentWithDefaultIsOptional() - { - $client = self::createClient(); - $crawler = $client->request('GET', '/nullable-arguments/with-default'); - - $this->assertSame('yes', $crawler->text()); - } - - public function testNullableArgumentIsOptional() - { - $client = self::createClient(); - $crawler = $client->request('GET', '/nullable-arguments/nullable'); - - $this->assertSame('yes', $crawler->text()); - } -} diff --git a/tests/Functional/Psr7RequestTest.php b/tests/Functional/Psr7RequestTest.php deleted file mode 100644 index 44d5bd88..00000000 --- a/tests/Functional/Psr7RequestTest.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; - -class Psr7RequestTest extends WebTestCase -{ - /** - * @dataProvider urlProvider - */ - public function testController($url) - { - $client = self::createClient(); - $crawler = $client->request('GET', $url); - - $this->assertEquals('ok', $crawler->filterXPath('//body')->html()); - } - - public static function urlProvider() - { - return [ - ['/action-arguments/normal/'], - ['/action-arguments/invoke/'], - ]; - } -}