Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: php-http/HttplugBundle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.34.0
Choose a base ref
...
head repository: php-http/HttplugBundle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.x
Choose a head ref
  • 9 commits
  • 27 files changed
  • 3 contributors

Commits on Sep 1, 2024

  1. throttle plugin requires a name

    dbu committed Sep 1, 2024
    Copy the full SHA
    5c3e184 View commit details
  2. fix build

    dbu committed Sep 1, 2024
    Copy the full SHA
    64362f1 View commit details
  3. Merge pull request #464 from php-http/fix-throttle

    throttle plugin requires a name
    dbu authored Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3fdfecc View commit details
  4. Throttle plugin configuration documentation

    Maxim Solovev authored and dbu committed Sep 1, 2024
    Copy the full SHA
    2ffa230 View commit details
  5. Merge pull request #465 from php-http/throttle-plugin-fixes

    Throttle plugin fixes
    dbu authored Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2db5b99 View commit details
  6. prepare release

    dbu committed Sep 1, 2024
    Copy the full SHA
    87c61d2 View commit details
  7. annotate classes that are not meant to be extended as final

    dbu committed Sep 1, 2024
    Copy the full SHA
    745ab83 View commit details
  8. Merge pull request #467 from php-http/annotate-final

    annotate classes that are not meant to be extended as final
    dbu authored Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    14b673c View commit details

Commits on Sep 4, 2024

  1. Remove deprecated spaceless filter (#470)

    * Remove deprecated spaceless filter
    
    > Since twig/twig 3.12: Twig Filter "spaceless" is deprecated
    
    * Remove spaces in test
    ruudk authored Sep 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3e36735 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ jobs:
- dependencies: "php-http/guzzle7-adapter"
php-version: "8.2"
symfony-deprecations-helper: "weak"
- dependencies: "php-http/guzzle7-adapter"
- dependencies: "php-http/guzzle7-adapter php-http/throttle-plugin"
php-version: "8.3"
symfony-deprecations-helper: "weak"

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,18 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee

# Version 1

# 1.34.3 - 2024-09-01

- Same as 1.34.2 but tagged on the 1.x banch instead of the feature branch.

# 1.34.2 - 2024-09-01

- More cleanup of the rate-limiter configuration. The service name is the full service name of the rate limiter, e.g. `limiter.my_name` when configuring `framework.rate_limiter.my_name`.

# 1.34.1 - 2024-09-01

- The rate-limiter name in the throttle plugin configuration is required.

# 1.34.0 - 2024-06-17

- Support to configure the throttle plugin.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -50,18 +50,19 @@
},
"require-dev": {
"guzzlehttp/psr7": "^1.7 || ^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
"matthiasnoback/symfony-config-test": "^4.3 || ^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0",
"nyholm/nsa": "^1.1",
"nyholm/psr7": "^1.2.1",
"php-http/cache-plugin": "^1.7",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
"phpunit/phpunit": "^9.6",
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/cache": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/http-foundation": "^4.4.19 || ^5.0 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^6.4.1",
"symfony/stopwatch": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/web-profiler-bundle": "^4.4.19 || ^5.0 || ^6.0 || ^7.0",
@@ -97,7 +98,7 @@
},
"prefer-stable": false,
"scripts": {
"test": "vendor/bin/simple-phpunit",
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
}
}
2 changes: 2 additions & 0 deletions src/ClientFactory/AutoDiscoveryFactory.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
* Use auto discovery to find a HTTP client.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class AutoDiscoveryFactory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/BuzzFactory.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class BuzzFactory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/CurlFactory.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class CurlFactory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/Guzzle5Factory.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class Guzzle5Factory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/Guzzle6Factory.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class Guzzle6Factory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/Guzzle7Factory.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class Guzzle7Factory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/ReactFactory.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class ReactFactory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/SocketFactory.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class SocketFactory implements ClientFactory
{
2 changes: 2 additions & 0 deletions src/ClientFactory/SymfonyFactory.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class SymfonyFactory implements ClientFactory
{
1 change: 1 addition & 0 deletions src/Collector/Collector.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class Collector extends DataCollector
{
1 change: 1 addition & 0 deletions src/Collector/Formatter.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class Formatter implements MessageFormatter
{
1 change: 1 addition & 0 deletions src/Collector/ProfileClient.php
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class ProfileClient implements HttpClient, HttpAsyncClient
{
1 change: 1 addition & 0 deletions src/Collector/ProfileClientFactory.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class ProfileClientFactory implements ClientFactory
{
1 change: 1 addition & 0 deletions src/Collector/ProfilePlugin.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class ProfilePlugin implements Plugin
{
1 change: 1 addition & 0 deletions src/Collector/StackPlugin.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*
* @internal
* @final
*/
class StackPlugin implements Plugin
{
2 changes: 2 additions & 0 deletions src/Collector/Twig/HttpMessageMarkupExtension.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class HttpMessageMarkupExtension extends AbstractExtension
{
26 changes: 20 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@
*
* @author David Buchmann <mail@davidbu.ch>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class Configuration implements ConfigurationInterface
{
@@ -616,7 +618,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
->end();
// End stopwatch plugin

$error = $children->arrayNode('error')
$children->arrayNode('error')
->canBeEnabled()
->addDefaultsIfNotSet()
->children()
@@ -625,14 +627,26 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
->end();
// End error plugin

$throttle = $children->arrayNode('throttle')
$children->arrayNode('throttle')
->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 service name from symfony/rate-limiter configuration. E.g. for a rate limiter http_client you specify limiter.http_client here')
->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
10 changes: 6 additions & 4 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@
/**
* @author David Buchmann <mail@davidbu.ch>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class HttplugExtension extends Extension
{
@@ -299,14 +301,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']);

2 changes: 2 additions & 0 deletions src/Discovery/ConfiguredClientsStrategy.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
* we can use the web debug toolbar for clients found with the discovery.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class ConfiguredClientsStrategy implements DiscoveryStrategy
{
2 changes: 2 additions & 0 deletions src/Discovery/ConfiguredClientsStrategyListener.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

/**
* @author Wouter de Jong <wouter@wouterj.nl>
*
* @final
*/
class ConfiguredClientsStrategyListener implements EventSubscriberInterface
{
2 changes: 2 additions & 0 deletions src/HttplugBundle.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
/**
* @author David Buchmann <mail@davidbu.ch>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*
* @final
*/
class HttplugBundle extends Bundle
{
18 changes: 8 additions & 10 deletions src/Resources/views/stack.html.twig
Original file line number Diff line number Diff line change
@@ -7,16 +7,14 @@
{% endif %}
<span class="label httplug-method httplug-method-{{ stack.requestMethod|lower }}">{{ stack.requestMethod }}</span>
</div>
{% apply spaceless %}
<div class="label httplug-stack-header-target">
<span class="httplug-scheme">{{ stack.requestScheme }}://</span>
<span class="httplug-host">{{ stack.requestHost }}</span>
{% if stack.requestPort not in [null, 80, 443] %}
<span class="httplug-port">:{{ stack.requestPort }}</span>
{% endif %}
<span class="httplug-target">{{ (stack.requestTarget|default('/') starts with '/' ? '' : '/') ~ stack.requestTarget }}</span>
</div>
{% endapply %}
<div class="label httplug-stack-header-target">
<span class="httplug-scheme">{{ stack.requestScheme }}://</span>
<span class="httplug-host">{{ stack.requestHost }}</span>
{% if stack.requestPort not in [null, 80, 443] %}
<span class="httplug-port">:{{ stack.requestPort }}</span>
{% endif %}
<span class="httplug-target">{{ (stack.requestTarget|default('/') starts with '/' ? '' : '/') ~ stack.requestTarget }}</span>
</div>
<div>
<span class="label httplug-duration">{{ stack.duration|number_format }} ms</span>
{% if stack.responseCode >= 400 and stack.responseCode <= 599 %}
2 changes: 1 addition & 1 deletion tests/Functional/ProfilerTest.php
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public function testShowProfiler(): void
$client->request('GET', '/_profiler/latest?panel=httplug');
$content = $client->getResponse()->getContent();
$this->assertStringContainsString(<<<HTML
<div class="label httplug-stack-header-target"><span class="httplug-scheme">https://</span><span class="httplug-host">jsonplaceholder.typicode.com</span><span class="httplug-target">/posts/1</span></div>
<span class="httplug-host">jsonplaceholder.typicode.com</span>
HTML, $content);
}
}
29 changes: 21 additions & 8 deletions tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;

use Http\Adapter\Guzzle7\Client;
use Http\Client\Common\Plugin\ThrottlePlugin;
use Http\Client\HttpClient;
use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder;
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
@@ -79,7 +80,7 @@ public function testConfigLoadService(): void

public function testClientPlugins(): void
{
$this->load([
$config = [
'clients' => [
'acme' => [
'factory' => 'httplug.factory.curl',
@@ -130,6 +131,11 @@ public function testClientPlugins(): void
'headers' => ['X-FOO'],
],
],
[
'query_defaults' => [
'parameters' => ['locale' => 'en'],
],
],
[
'request_seekable_body' => [
'use_file_buffer' => true,
@@ -138,11 +144,6 @@ public function testClientPlugins(): void
[
'response_seekable_body' => true,
],
[
'query_defaults' => [
'parameters' => ['locale' => 'en'],
],
],
[
'authentication' => [
'my_basic' => [
@@ -165,7 +166,16 @@ public function testClientPlugins(): void
],
],
],
]);
];
if (class_exists(ThrottlePlugin::class)) {
$config['clients']['acme']['plugins'][] = [
'throttle' => [
'name' => 'limiter.test',
],
];
}

$this->load($config);

$plugins = [
'httplug.client.acme.plugin.decoder',
@@ -178,13 +188,16 @@ public function testClientPlugins(): void
'httplug.client.acme.plugin.header_defaults',
'httplug.client.acme.plugin.header_set',
'httplug.client.acme.plugin.header_remove',
'httplug.client.acme.plugin.query_defaults',
'httplug.client.acme.plugin.request_seekable_body',
'httplug.client.acme.plugin.response_seekable_body',
'httplug.client.acme.plugin.query_defaults',
'httplug.client.acme.authentication.my_basic',
'httplug.client.acme.plugin.cache',
'httplug.client.acme.plugin.error',
];
if (\class_exists(ThrottlePlugin::class)) {
$plugins[] = 'httplug.client.acme.plugin.throttle';
}
$pluginReferences = array_map(function ($id) {
return new Reference($id);
}, $plugins);