From 872a3430ead8fd37b15aea332cc5de3b1d99f3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Wed, 10 Mar 2021 19:00:23 +0100 Subject: [PATCH] Add compiler pass class to ensure that required PSR-17 factories are defined --- CHANGELOG.md | 3 ++ src/AjgarlagPsrHttpMessageBundle.php | 2 + .../Compiler/AssertDefinedPsr17Factories.php | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/DependencyInjection/Compiler/AssertDefinedPsr17Factories.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dad500..f07a232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased](https://github.com/ajgarlag/psr-http-message-bundle/compare/1.2.0...main) +### Added +- Add compiler pass class to ensure that required PSR-17 factories are defined + ## [1.2.0](https://github.com/ajgarlag/psr-http-message-bundle/compare/1.1.2...1.2.0) - 2021-02-19 ### Added diff --git a/src/AjgarlagPsrHttpMessageBundle.php b/src/AjgarlagPsrHttpMessageBundle.php index 34aef09..186d511 100644 --- a/src/AjgarlagPsrHttpMessageBundle.php +++ b/src/AjgarlagPsrHttpMessageBundle.php @@ -12,6 +12,7 @@ namespace Ajgarlag\Bundle\PsrHttpMessageBundle; +use Ajgarlag\Bundle\PsrHttpMessageBundle\DependencyInjection\Compiler\AssertDefinedPsr17Factories; use Ajgarlag\Bundle\PsrHttpMessageBundle\DependencyInjection\Compiler\RegisterHttpMessageFactoriesPass; use Ajgarlag\Bundle\PsrHttpMessageBundle\DependencyInjection\Compiler\RegisterNyholmPsr17FactoriesPass; use Ajgarlag\Bundle\PsrHttpMessageBundle\DependencyInjection\Compiler\TagArgumentValueResolverPass; @@ -29,6 +30,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new TagArgumentValueResolverPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1); $container->addCompilerPass(new RegisterHttpMessageFactoriesPass()); $container->addCompilerPass(new RegisterNyholmPsr17FactoriesPass()); + $container->addCompilerPass(new AssertDefinedPsr17Factories()); $container->addCompilerPass(new TagViewEventListenerPass()); } } diff --git a/src/DependencyInjection/Compiler/AssertDefinedPsr17Factories.php b/src/DependencyInjection/Compiler/AssertDefinedPsr17Factories.php new file mode 100644 index 0000000..734d1a3 --- /dev/null +++ b/src/DependencyInjection/Compiler/AssertDefinedPsr17Factories.php @@ -0,0 +1,40 @@ +has($requiredInterface)) { + throw new LogicException(sprintf('Service for PSR-17 factory "%s" not found. Run "composer require nyholm/psr7" to install the recommended implementation.', $requiredInterface)); + } + } + } +}