diff --git a/.travis.yml b/.travis.yml index 6c67bbc7..d18d58ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,15 +8,13 @@ cache: - .phpunit php: - - 5.5 - - 5.6 - - 7.0 - 7.1 - 7.2 + - 7.3 matrix: include: - - php: 7.0 + - php: 7.2 env: deps=low fast_finish: true diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 288a692f..e252d45c 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -11,6 +11,7 @@ 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; @@ -76,7 +77,7 @@ public function getConfigTreeBuilder() ->arrayNode('psr_message') ->addDefaultsIfNotSet() ->children() - ->booleanNode('enabled')->defaultValue(interface_exists('Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface') && class_exists('Zend\Diactoros\ServerRequestFactory'))->end() + ->booleanNode('enabled')->defaultValue(interface_exists(HttpFoundationFactoryInterface::class))->end() ->end() ->end() ->arrayNode('templating') diff --git a/DependencyInjection/SensioFrameworkExtraExtension.php b/DependencyInjection/SensioFrameworkExtraExtension.php index 26f6c10f..d19fa680 100644 --- a/DependencyInjection/SensioFrameworkExtraExtension.php +++ b/DependencyInjection/SensioFrameworkExtraExtension.php @@ -11,16 +11,17 @@ namespace Sensio\Bundle\FrameworkExtraBundle\DependencyInjection; +use Psr\Http\Message\StreamFactoryInterface; use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\ClassExistenceResource; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Security\Core\Authorization\ExpressionLanguage as SecurityExpressionLanguage; -use Zend\Diactoros\ServerRequestFactory; /** * @author Fabien Potencier @@ -148,8 +149,8 @@ public function load(array $configs, ContainerBuilder $container) if ($config['psr_message']['enabled']) { $loader->load('psr7.xml'); - if (!class_exists(ServerRequestFactory::class)) { - $definitionsToRemove[] = 'sensio_framework_extra.psr7.argument_value_resolver.server_request'; + if (!interface_exists(StreamFactoryInterface::class)) { + throw new LogicException('PSR-7 support cannot be enabled as the required dependencies are not installed. Try running "composer require nyholm/psr7".'); } } diff --git a/Resources/config/psr7.xml b/Resources/config/psr7.xml index 8d32be36..c56b0cb3 100644 --- a/Resources/config/psr7.xml +++ b/Resources/config/psr7.xml @@ -5,7 +5,12 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + + + + + + @@ -17,5 +22,12 @@ + + + + + + + diff --git a/Resources/doc/index.rst b/Resources/doc/index.rst index fb1215f5..48b966e8 100644 --- a/Resources/doc/index.rst +++ b/Resources/doc/index.rst @@ -189,27 +189,27 @@ 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 `Zend Diactoros`_ must be installed: +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 zendframework/zend-diactoros + $ 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; - use Zend\Diactoros\Response; class DefaultController { - public function indexAction(ServerRequestInterface $request) + public function indexAction(ServerRequestInterface $request, ResponseFactoryInterface $responseFactory) { // Interact with the PSR-7 request - $response = new Response(); + $response = $responseFactory->createResponse(); // Interact with the PSR-7 response return $response; @@ -222,4 +222,4 @@ 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 -.. _`Zend Diactoros`: https://github.com/zendframework/zend-diactoros +.. _`autowiring aliases for PSR-17`: https://github.com/symfony/recipes/blob/master/nyholm/psr7/1.0/config/packages/nyholm_psr7.yaml diff --git a/composer.json b/composer.json index e9d07f4d..8312973e 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ } ], "require": { + "php": ">=7.1.3", "symfony/config": "^3.3|^4.0", "symfony/framework-bundle": "^3.4|^4.0", "symfony/dependency-injection": "^3.3|^4.0", @@ -20,7 +21,7 @@ "require-dev": { "symfony/expression-language": "^3.3|^4.0", "symfony/finder": "^3.3|^4.0", - "symfony/psr-http-message-bridge": "^0.3", + "symfony/psr-http-message-bridge": "^1.1", "symfony/security-bundle": "^3.3|^4.0", "symfony/yaml": "^3.3|^4.0", "symfony/twig-bundle": "^3.3|^4.0", @@ -28,11 +29,11 @@ "symfony/browser-kit": "^3.3|^4.0", "symfony/phpunit-bridge": "^3.4.19|^4.1.8", "symfony/dom-crawler": "^3.3|^4.0", - "zendframework/zend-diactoros": "^1.3", "doctrine/doctrine-bundle": "^1.6", "doctrine/orm": "^2.5", "symfony/monolog-bundle": "^3.2", - "symfony/monolog-bridge": "^3.0|^4.0" + "symfony/monolog-bridge": "^3.0|^4.0", + "nyholm/psr7": "^1.1" }, "suggest": { "symfony/psr-http-message-bridge": "To use the PSR-7 converters",