Skip to content

Commit

Permalink
throttle plugin requires a name
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Sep 1, 2024
1 parent 5380dad commit 5c3e184
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
->end();
// End stopwatch plugin

$error = $children->arrayNode('error')
$children->arrayNode('error')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down

0 comments on commit 5c3e184

Please # to comment.