-
Notifications
You must be signed in to change notification settings - Fork 50
add ThrottlePlugin #460
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
add ThrottlePlugin #460
Conversation
@dbu Please, can you check my PR. If you have some question, just ask me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, nice work! what happens if somebody would install the old version of throttle plugin with these changes? with the named parameters, we would get an error from symfony about the new parameters, i think? if that is correct, we should add a conflict
in composer.json to avoid installing this with a too old version.
can you please add to the HttplugExtensionTest::testClientPlugins to enable the throttle plugin and verify the service is created (the test is generic, just add the config and the expected service name)
to keep the documentation up to date, can you please also add to https://github.com/php-http/documentation/blob/main/integrations/symfony-bundle.rst#list-of-services and https://github.com/php-http/documentation/blob/main/integrations/symfony-full-configuration.rst ?
@@ -292,6 +294,28 @@ private function configurePluginByName($name, Definition $definition, array $con | |||
|
|||
break; | |||
|
|||
case 'throttle': | |||
if (!\interface_exists(LimiterInterface::class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is redundant. the throttle-plugin repository depends on symfony/rate-limiter. checking for the ThrottlePlugin is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
I tried, but minimal supported version for bundle, it's 7.3, but throttle plugin works only with 7.4 and upper, and I can not run this test in 7.3. I think we can add this only in v2, if you want. |
I think you can make this work if you use positional arguments instead of named |
@ostrolucky Possible, but is it necessary, because there are no backwards compatible changes? |
Well I believe it will be backwards compatible with positional arguments instead of named ones. |
@ostrolucky It will work, but the options won't work as expected, which can also be confusing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding the test with the plugin: i see. then lets add that in the 2.x branch. i will merge this now and then merge 1.x to 2.x
@dbu thanks, please, create new release |
on it, on it ;-) https://github.com/php-http/HttplugBundle/releases/tag/1.34.0 and merging to 2.x in #461 (i added the test right away) |
->canBeEnabled() | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->scalarNode('name')->end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at the test failure in #461: what is the name here? and what is key?
the name is not made required, but the configuration class does not handle a missing name field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbu You need to set name, name this is required option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we are missing isRequired()
can you please also add an info()
as well with an explanation what this name is? the name of what thing do we specify here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, check #462
$key = $config['name'] ? '.'.$config['name'] : ''; | ||
$container | ||
->register($serviceId.$key, LimiterInterface::class) | ||
->setFactory([new Reference('limiter.'.$config['name']), 'create']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not check if the name is set or not. and if the name is empty, it will use limiter.
, is that the intention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbu No, it was my mistake, I assume that if the default value is not specified, then it is required by default
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'] : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if name is required, this check is for the special case where name is set to ''
? below it would still do strange things when name is ''
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and i think symfony configuration will not allow ''
on something that is set to be required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, check #462
What's in this PR?
Add config settings for ThrottlePlugin
Why?
Adding the plugin without using configurations causes inconvenience.
Example