|
10 | 10 | use Http\Client\Common\HttpMethodsClient;
|
11 | 11 | use Http\Client\Common\HttpMethodsClientInterface;
|
12 | 12 | use Http\Client\Common\Plugin\AuthenticationPlugin;
|
| 13 | +use Http\Client\Common\Plugin\ThrottlePlugin; |
13 | 14 | use Http\Client\Common\PluginClient;
|
14 | 15 | use Http\Client\Common\PluginClientFactory;
|
15 | 16 | use Http\Client\HttpAsyncClient;
|
|
35 | 36 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
36 | 37 | use Symfony\Component\DependencyInjection\Reference;
|
37 | 38 | use Symfony\Component\HttpKernel\Kernel;
|
| 39 | +use Symfony\Component\RateLimiter\LimiterInterface; |
38 | 40 | use Twig\Environment as TwigEnvironment;
|
39 | 41 |
|
40 | 42 | /**
|
@@ -292,6 +294,24 @@ private function configurePluginByName($name, Definition $definition, array $con
|
292 | 294 |
|
293 | 295 | break;
|
294 | 296 |
|
| 297 | + case 'throttle': |
| 298 | + if (!\class_exists(ThrottlePlugin::class)) { |
| 299 | + throw new InvalidConfigurationException('You need to require the Throttle Plugin to be able to use it: "composer require php-http/throttle-plugin".'); |
| 300 | + } |
| 301 | + |
| 302 | + $key = $config['name'] ? '.'.$config['name'] : ''; |
| 303 | + $container |
| 304 | + ->register($serviceId.$key, LimiterInterface::class) |
| 305 | + ->setFactory([new Reference('limiter.'.$config['name']), 'create']) |
| 306 | + ->addArgument($config['key']) |
| 307 | + ->setPublic(false); |
| 308 | + |
| 309 | + $definition->replaceArgument(0, new Reference($serviceId.$key)); |
| 310 | + $definition->setArgument('$tokens', $config['tokens']); |
| 311 | + $definition->setArgument('$maxTime', $config['max_time']); |
| 312 | + |
| 313 | + break; |
| 314 | + |
295 | 315 | /* client specific plugins */
|
296 | 316 |
|
297 | 317 | case 'add_host':
|
|
0 commit comments