Skip to content

Commit 5c3e184

Browse files
committed
throttle plugin requires a name
1 parent 5380dad commit 5c3e184

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
# Version 1
66

7+
# 1.34.1 - 2024-09-01
8+
9+
- The rate-limiter name in the throttle plugin configuration is required.
10+
711
# 1.34.0 - 2024-06-17
812

913
- Support to configure the throttle plugin.

src/DependencyInjection/Configuration.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
616616
->end();
617617
// End stopwatch plugin
618618

619-
$error = $children->arrayNode('error')
619+
$children->arrayNode('error')
620620
->canBeEnabled()
621621
->addDefaultsIfNotSet()
622622
->children()
@@ -625,11 +625,14 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
625625
->end();
626626
// End error plugin
627627

628-
$throttle = $children->arrayNode('throttle')
628+
$children->arrayNode('throttle')
629629
->canBeEnabled()
630630
->addDefaultsIfNotSet()
631631
->children()
632-
->scalarNode('name')->end()
632+
->scalarNode('name')
633+
->info('The name of the configured symfony/rate-limiter to use')
634+
->isRequired()
635+
->end()
633636
->scalarNode('key')->defaultNull()->end()
634637
->integerNode('tokens')->defaultValue(1)->end()
635638
->floatNode('max_time')->defaultNull()->end()

src/DependencyInjection/HttplugExtension.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,13 @@ private function configurePluginByName($name, Definition $definition, array $con
299299
throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".');
300300
}
301301

302-
$key = $config['name'] ? '.'.$config['name'] : '';
303302
$container
304-
->register($serviceId.$key, LimiterInterface::class)
303+
->register($serviceId.$config['name'], LimiterInterface::class)
305304
->setFactory([new Reference('limiter.'.$config['name']), 'create'])
306305
->addArgument($config['key'])
307306
->setPublic(false);
308307

309-
$definition->replaceArgument(0, new Reference($serviceId.$key));
308+
$definition->replaceArgument(0, new Reference($serviceId.$config['name']));
310309
$definition->setArgument('$tokens', $config['tokens']);
311310
$definition->setArgument('$maxTime', $config['max_time']);
312311

0 commit comments

Comments
 (0)