From 5c3e184b1e96058c074c8d20a09ee3a708ba1f50 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 09:07:16 +0200 Subject: [PATCH] throttle plugin requires a name --- CHANGELOG.md | 4 ++++ src/DependencyInjection/Configuration.php | 9 ++++++--- src/DependencyInjection/HttplugExtension.php | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccaff89d..a4012550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # Version 1 +# 1.34.1 - 2024-09-01 + +- The rate-limiter name in the throttle plugin configuration is required. + # 1.34.0 - 2024-06-17 - Support to configure the throttle plugin. diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bd70c712..76b13751 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -616,7 +616,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA ->end(); // End stopwatch plugin - $error = $children->arrayNode('error') + $children->arrayNode('error') ->canBeEnabled() ->addDefaultsIfNotSet() ->children() @@ -625,11 +625,14 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA ->end(); // End error plugin - $throttle = $children->arrayNode('throttle') + $children->arrayNode('throttle') ->canBeEnabled() ->addDefaultsIfNotSet() ->children() - ->scalarNode('name')->end() + ->scalarNode('name') + ->info('The name of the configured symfony/rate-limiter to use') + ->isRequired() + ->end() ->scalarNode('key')->defaultNull()->end() ->integerNode('tokens')->defaultValue(1)->end() ->floatNode('max_time')->defaultNull()->end() diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index cdcbfcf0..ce88c008 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -299,14 +299,13 @@ private function configurePluginByName($name, Definition $definition, array $con throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".'); } - $key = $config['name'] ? '.'.$config['name'] : ''; $container - ->register($serviceId.$key, LimiterInterface::class) + ->register($serviceId.$config['name'], LimiterInterface::class) ->setFactory([new Reference('limiter.'.$config['name']), 'create']) ->addArgument($config['key']) ->setPublic(false); - $definition->replaceArgument(0, new Reference($serviceId.$key)); + $definition->replaceArgument(0, new Reference($serviceId.$config['name'])); $definition->setArgument('$tokens', $config['tokens']); $definition->setArgument('$maxTime', $config['max_time']);