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 1 commit
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 configuration name from rate_limiter.yaml')->end()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will tricky when a user configures their own service for a rate limiter factory and does not call it limiter.{name}.

in other places, we ask for a full service name for things. i think i would prefer to do the same here:

Suggested change
->scalarNode('name')->isRequired()->info('Rate limiter configuration name from rate_limiter.yaml')->end()
->scalarNode('name')->isRequired()->info('Rate limiter factory service name, e.g. limiter.http_client for a rate limiter called http_client')->end()

wdyt? if we change it here, we also need to adjust the extension class.

and now that i understand what it is, it should be called more specific limiter_name. or while we do change it to be the service, limiter_service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu Symfony automatic create factory in container, I just have this config
image

I think using just "name" more understandable than whole name in container, like "limiter.http_client"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, when one configures in framework bundle, that creates the services with this naming pattern.

the thing is that a user might configure their own service rather than use the framework configuration, e.g. when they have a custom implementation of the rate limiter. and for that i think its more consistent with the rest of the bundle to have the full service name.

->scalarNode('key')->defaultNull()->info('A unique key for using one rate limiter name for different clients')->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
6 changes: 3 additions & 3 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)
->register($limiterServiceId, 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($limiterServiceId));
$definition->setArgument('$tokens', $config['tokens']);
$definition->setArgument('$maxTime', $config['max_time']);

Expand Down