Skip to content

Throttle plugin small fixes #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,10 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
->scalarNode('name')->end()
->scalarNode('key')->defaultNull()->end()
->integerNode('tokens')->defaultValue(1)->end()
->floatNode('max_time')->defaultNull()->end()
->scalarNode('name')->isRequired()->info('Rate limiter factory service name, e.g. limiter.http_client for a rate limiter called http_client')->end()
->scalarNode('key')->defaultNull()->info('Key to avoid sharing this rate limiter with other clients or other services. You can use the name of the client for example.')->end()
->integerNode('tokens')->defaultValue(1)->info('How many tokens spending per request')->end()
->floatNode('max_time')->defaultNull()->info('Maximum accepted waiting time in seconds')->end()
->end()
->end();
// End throttle plugin
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ 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'] : '';
$limiterServiceId = $serviceId.'.'.$config['name'];
$container
->register($serviceId.$key, LimiterInterface::class)
->setFactory([new Reference('limiter.'.$config['name']), 'create'])
->register($limiterServiceId, LimiterInterface::class)
->setFactory([new Reference($config['name']), 'create'])
->addArgument($config['key'])
->setPublic(false);

$definition->replaceArgument(0, new Reference($serviceId.$key));
$definition->replaceArgument(0, new Reference($limiterServiceId));
$definition->setArgument('$tokens', $config['tokens']);
$definition->setArgument('$maxTime', $config['max_time']);

Expand Down