Skip to content

Commit 8b1d3fe

Browse files
Replace xml with php config
Convert all service configuration files from deprecated XML format to PHP format to eliminate Symfony deprecation warnings and for Symfony 8.0 compatibility.
1 parent 5aba499 commit 8b1d3fe

File tree

12 files changed

+459
-313
lines changed

12 files changed

+459
-313
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
# Version 2
66

7+
# 2.2.0 - 2025-12-08
8+
- Replaced XML configuration with PHP configuration.
9+
710
# 2.1.0 - 2024-11-24
811

912
- Added [PluginConfigurator](https://docs.php-http.org/en/latest/integrations/symfony-bundle.html#configure-a-custom-plugin)

src/DependencyInjection/HttplugExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use Symfony\Component\DependencyInjection\ContainerBuilder;
3434
use Symfony\Component\DependencyInjection\Definition;
3535
use Symfony\Component\DependencyInjection\Extension\Extension;
36-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
36+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
3737
use Symfony\Component\DependencyInjection\Reference;
3838
use Symfony\Component\RateLimiter\LimiterInterface;
3939
use Twig\Environment as TwigEnvironment;
@@ -56,12 +56,12 @@ public function load(array $configs, ContainerBuilder $container): void
5656
$configuration = $this->getConfiguration($configs, $container);
5757
$config = $this->processConfiguration($configuration, $configs);
5858

59-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
59+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
6060

61-
$loader->load('services.xml');
62-
$loader->load('plugins.xml');
61+
$loader->load('services.php');
62+
$loader->load('plugins.php');
6363
if (\class_exists(MockClient::class)) {
64-
$loader->load('mock-client.xml');
64+
$loader->load('mock-client.php');
6565
}
6666

6767
// Register default services
@@ -79,7 +79,7 @@ public function load(array $configs, ContainerBuilder $container): void
7979
// Configure toolbar
8080
$profilingEnabled = $this->isConfigEnabled($container, $config['profiling']);
8181
if ($profilingEnabled) {
82-
$loader->load('data-collector.xml');
82+
$loader->load('data-collector.php');
8383

8484
if (!empty($config['profiling']['formatter'])) {
8585
// Add custom formatter
@@ -117,7 +117,7 @@ public function load(array $configs, ContainerBuilder $container): void
117117
throw new InvalidConfigurationException('You need to require the VCR plugin to be able to use it: "composer require --dev php-http/vcr-plugin".');
118118
}
119119

120-
$loader->load('vcr-plugin.xml');
120+
$loader->load('vcr-plugin.php');
121121
}
122122
}
123123

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
6+
7+
use Http\HttplugBundle\Collector\Collector;
8+
use Http\HttplugBundle\Collector\Formatter;
9+
use Http\HttplugBundle\Collector\PluginClientFactory;
10+
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
11+
use Http\HttplugBundle\Collector\ProfileClient;
12+
use Http\HttplugBundle\Collector\ProfileClientFactory;
13+
use Http\HttplugBundle\Collector\StackPlugin;
14+
use Http\HttplugBundle\Collector\Twig\HttpMessageMarkupExtension;
15+
use Http\Message\Formatter\CurlCommandFormatter;
16+
use Http\Message\Formatter\FullHttpMessageFormatter;
17+
18+
return static function (ContainerConfigurator $container): void {
19+
$services = $container->services();
20+
21+
$services->set('httplug.formatter.full_http_message', FullHttpMessageFormatter::class);
22+
23+
$services->set('httplug.collector.formatter', Formatter::class)
24+
->args([
25+
service('httplug.formatter.full_http_message'),
26+
inline_service(CurlCommandFormatter::class),
27+
]);
28+
29+
$services->set('httplug.collector.collector', Collector::class)
30+
->tag('data_collector', [
31+
'template' => '@Httplug/webprofiler.html.twig',
32+
'priority' => 200,
33+
'id' => 'httplug',
34+
])
35+
->tag('kernel.reset', ['method' => 'reset']);
36+
37+
$services->set('httplug.plugin.stack', StackPlugin::class)
38+
->args([
39+
service('httplug.collector.collector'),
40+
service('httplug.collector.formatter'),
41+
])
42+
->abstract();
43+
44+
$services->set('httplug.collector.twig.http_message', HttpMessageMarkupExtension::class)
45+
->args([
46+
service('var_dumper.cloner')->nullOnInvalid(),
47+
service('var_dumper.html_dumper')->nullOnInvalid(),
48+
])
49+
->tag('twig.extension');
50+
51+
// Discovered clients
52+
$services->set('httplug.collector.auto_discovered_client', ProfileClient::class)
53+
->decorate('httplug.auto_discovery.auto_discovered_client')
54+
->args([
55+
service('httplug.collector.auto_discovered_client.inner'),
56+
service('httplug.collector.collector'),
57+
service('httplug.collector.formatter'),
58+
service('debug.stopwatch'),
59+
]);
60+
61+
$services->set('httplug.collector.auto_discovered_async', ProfileClient::class)
62+
->decorate('httplug.auto_discovery.auto_discovered_async')
63+
->args([
64+
service('httplug.collector.auto_discovered_async.inner'),
65+
service('httplug.collector.collector'),
66+
service('httplug.collector.formatter'),
67+
service('debug.stopwatch'),
68+
]);
69+
70+
// ClientFactories
71+
$services->set('httplug.collector.factory.auto', ProfileClientFactory::class)
72+
->decorate('httplug.factory.auto')
73+
->args([
74+
service('httplug.collector.factory.auto.inner'),
75+
service('httplug.collector.collector'),
76+
service('httplug.collector.formatter'),
77+
service('debug.stopwatch'),
78+
]);
79+
80+
$services->set('httplug.collector.factory.buzz', ProfileClientFactory::class)
81+
->decorate('httplug.factory.buzz')
82+
->args([
83+
service('httplug.collector.factory.buzz.inner'),
84+
service('httplug.collector.collector'),
85+
service('httplug.collector.formatter'),
86+
service('debug.stopwatch'),
87+
]);
88+
89+
$services->set('httplug.collector.factory.curl', ProfileClientFactory::class)
90+
->decorate('httplug.factory.curl')
91+
->args([
92+
service('httplug.collector.factory.curl.inner'),
93+
service('httplug.collector.collector'),
94+
service('httplug.collector.formatter'),
95+
service('debug.stopwatch'),
96+
]);
97+
98+
$services->set('httplug.collector.factory.guzzle6', ProfileClientFactory::class)
99+
->decorate('httplug.factory.guzzle6')
100+
->args([
101+
service('httplug.collector.factory.guzzle6.inner'),
102+
service('httplug.collector.collector'),
103+
service('httplug.collector.formatter'),
104+
service('debug.stopwatch'),
105+
]);
106+
107+
$services->set('httplug.collector.factory.guzzle7', ProfileClientFactory::class)
108+
->decorate('httplug.factory.guzzle7')
109+
->args([
110+
service('httplug.collector.factory.guzzle7.inner'),
111+
service('httplug.collector.collector'),
112+
service('httplug.collector.formatter'),
113+
service('debug.stopwatch'),
114+
]);
115+
116+
$services->set('httplug.collector.factory.react', ProfileClientFactory::class)
117+
->decorate('httplug.factory.react')
118+
->args([
119+
service('httplug.collector.factory.react.inner'),
120+
service('httplug.collector.collector'),
121+
service('httplug.collector.formatter'),
122+
service('debug.stopwatch'),
123+
]);
124+
125+
$services->set('httplug.collector.factory.socket', ProfileClientFactory::class)
126+
->decorate('httplug.factory.socket')
127+
->args([
128+
service('httplug.collector.factory.socket.inner'),
129+
service('httplug.collector.collector'),
130+
service('httplug.collector.formatter'),
131+
service('debug.stopwatch'),
132+
]);
133+
134+
$services->set(\Http\Client\Common\PluginClientFactory::class, PluginClientFactory::class)
135+
->args([
136+
service('httplug.collector.collector'),
137+
service('httplug.collector.formatter'),
138+
service('debug.stopwatch'),
139+
]);
140+
141+
$services->set(PluginClientFactoryListener::class)
142+
->args([
143+
service(\Http\Client\Common\PluginClientFactory::class),
144+
])
145+
->tag('kernel.event_subscriber');
146+
};

src/Resources/config/data-collector.xml

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
6+
7+
use Http\HttplugBundle\ClientFactory\MockFactory;
8+
use Http\Mock\Client;
9+
10+
return static function (ContainerConfigurator $container): void {
11+
$services = $container->services();
12+
13+
$services->set('httplug.client.mock', Client::class)
14+
->public();
15+
16+
$services->alias(Client::class, 'httplug.client.mock')
17+
->public();
18+
19+
$services->set('httplug.factory.mock', MockFactory::class)
20+
->call('setClient', [
21+
service('httplug.client.mock'),
22+
]);
23+
};

src/Resources/config/mock-client.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)