Skip to content

Commit 3fdfecc

Browse files
authored
Merge pull request #464 from php-http/fix-throttle
throttle plugin requires a name
2 parents 5380dad + 64362f1 commit 3fdfecc

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
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.

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@
5050
},
5151
"require-dev": {
5252
"guzzlehttp/psr7": "^1.7 || ^2.0",
53-
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
53+
"matthiasnoback/symfony-config-test": "^4.3 || ^5.0",
54+
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0",
5455
"nyholm/nsa": "^1.1",
5556
"nyholm/psr7": "^1.2.1",
5657
"php-http/cache-plugin": "^1.7",
5758
"php-http/mock-client": "^1.2",
5859
"php-http/promise": "^1.0",
60+
"phpunit/phpunit": "^9.6",
5961
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6062
"symfony/cache": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6163
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6264
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6365
"symfony/http-foundation": "^4.4.19 || ^5.0 || ^6.0 || ^7.0",
64-
"symfony/phpunit-bridge": "^6.4.1",
6566
"symfony/stopwatch": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6667
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
6768
"symfony/web-profiler-bundle": "^4.4.19 || ^5.0 || ^6.0 || ^7.0",
@@ -97,7 +98,7 @@
9798
},
9899
"prefer-stable": false,
99100
"scripts": {
100-
"test": "vendor/bin/simple-phpunit",
101-
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
101+
"test": "vendor/bin/phpunit",
102+
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
102103
}
103104
}

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)