Skip to content

Commit 1036c17

Browse files
authored
Add Symfony 6 support (#409)
1 parent afd8aaf commit 1036c17

File tree

13 files changed

+83
-171
lines changed

13 files changed

+83
-171
lines changed

.github/workflows/continuous-integration.yml

-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ jobs:
5555
symfony-deprecations-helper: "weak"
5656

5757
# Test maintained versions of Symfony
58-
- dependencies: "php-http/guzzle6-adapter"
59-
symfony-require: "3.4.*"
60-
php-version: "7.3"
61-
symfony-deprecations-helper: "weak"
6258
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^4.4"
6359
symfony-require: "4.4.*"
6460
php-version: "7.3"

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5-
# 1.24.1 - TBD
6-
- Fixed deprecation notice in PHP 8.1 by adding `= null` to `\Http\HttplugBundle\Collector\Twig\HttpMessageMarkupExtension`
7-
-
5+
# 1.25.0 - TBD
6+
- Added PHP 8.1 support
7+
- Added Symfony 6 support
8+
- Removed Symfony 3.x support
9+
810
# 1.24.0 - 2021-10-23
911
- Changed stopwatch category from default to "httplug", so it's more prominent on Execution timeline view
1012
- Changed tab texts inside profiler so that it shows ports in URL in case it's non-standard

composer.json

+15-16
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
"php": "^7.3 || ^8.0",
2929
"php-http/client-common": "^1.9 || ^2.0",
3030
"php-http/client-implementation": "^1.0",
31-
"php-http/discovery": "^1.0",
31+
"php-http/discovery": "^1.14",
3232
"php-http/httplug": "^1.0 || ^2.0",
3333
"php-http/logger-plugin": "^1.1",
3434
"php-http/message": "^1.4",
3535
"php-http/message-factory": "^1.0.2",
3636
"php-http/stopwatch-plugin": "^1.2",
3737
"psr/http-message": "^1.0",
38-
"symfony/config": "^3.4.34 || ^4.2.12 || ^5.0",
39-
"symfony/dependency-injection": "^3.4.34 || ^4.2.12 || ^5.0",
40-
"symfony/event-dispatcher": "^3.4.34 || ^4.2.12 || ^5.0",
41-
"symfony/http-kernel": "^3.4.34 || ^4.2.12 || ^5.0",
42-
"symfony/options-resolver": "^3.4.34 || ^4.2.12 || ^5.0"
38+
"symfony/config": "^4.4 || ^5.0 || ^6.0",
39+
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
40+
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
41+
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
42+
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0"
4343
},
4444
"conflict": {
4545
"php-http/guzzle6-adapter": "<1.1",
@@ -53,16 +53,15 @@
5353
"php-http/cache-plugin": "^1.7",
5454
"php-http/mock-client": "^1.2",
5555
"php-http/promise": "^1.0",
56-
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
57-
"symfony/browser-kit": "^3.4.34 || ^4.2.12 || ^5.0",
58-
"symfony/cache": "^3.4.35 || ~4.2.12 || ^4.3.8 || ^5.0",
59-
"symfony/dom-crawler": "^3.4.34 || ^4.2.12 || ^5.0",
60-
"symfony/framework-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
61-
"symfony/http-foundation": "^3.4.35 || ~4.2.12 || ^4.3.8 || ^5.0",
56+
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
57+
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
58+
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
59+
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
60+
"symfony/http-foundation": "^4.4.19 || ^5.0 || ^6.0",
6261
"symfony/phpunit-bridge": "^5.3",
63-
"symfony/stopwatch": "^3.4.34 || ^4.2.12 || ^5.0",
64-
"symfony/twig-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
65-
"symfony/web-profiler-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
62+
"symfony/stopwatch": "^4.4 || ^5.0 || ^6.0",
63+
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
64+
"symfony/web-profiler-bundle": "^4.4.19 || ^5.0 || ^6.0",
6665
"twig/twig": "^1.41 || ^2.10 || ^3.0"
6766
},
6867
"suggest": {
@@ -95,7 +94,7 @@
9594
]
9695
},
9796
"minimum-stability": "dev",
98-
"prefer-stable": true,
97+
"prefer-stable": false,
9998
"scripts": {
10099
"test": "vendor/bin/simple-phpunit",
101100
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"

src/Collector/Collector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function reset()
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function getName()
46+
public function getName(): string
4747
{
4848
return 'httplug';
4949
}

src/Collector/PluginClientFactoryListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function onEvent(PluginClientFactoryListenerEventClass $e)
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public static function getSubscribedEvents()
51+
public static function getSubscribedEvents(): array
5252
{
5353
return [
5454
'kernel.request' => ['onEvent', 1024],

src/DependencyInjection/Configuration.php

+6-31
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@ public function __construct($debug)
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function getConfigTreeBuilder()
57+
public function getConfigTreeBuilder(): TreeBuilder
5858
{
5959
$treeBuilder = new TreeBuilder('httplug');
60-
// Keep compatibility with symfony/config < 4.2
61-
if (!method_exists($treeBuilder, 'getRootNode')) {
62-
$rootNode = $treeBuilder->root('httplug');
63-
} else {
64-
$rootNode = $treeBuilder->getRootNode();
65-
}
60+
$rootNode = $treeBuilder->getRootNode();
6661

6762
$this->configureClients($rootNode);
6863
$this->configureSharedPlugins($rootNode);
@@ -274,12 +269,7 @@ private function configureSharedPlugins(ArrayNodeDefinition $root)
274269
private function createClientPluginNode()
275270
{
276271
$treeBuilder = new TreeBuilder('plugins');
277-
// Keep compatibility with symfony/config < 4.2
278-
if (!method_exists($treeBuilder, 'getRootNode')) {
279-
$node = $treeBuilder->root('plugins');
280-
} else {
281-
$node = $treeBuilder->getRootNode();
282-
}
272+
$node = $treeBuilder->getRootNode();
283273

284274
/** @var ArrayNodeDefinition $pluginList */
285275
$pluginList = $node
@@ -610,12 +600,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
610600
private function createAuthenticationPluginNode()
611601
{
612602
$treeBuilder = new TreeBuilder('authentication');
613-
// Keep compatibility with symfony/config < 4.2
614-
if (!method_exists($treeBuilder, 'getRootNode')) {
615-
$node = $treeBuilder->root('authentication');
616-
} else {
617-
$node = $treeBuilder->getRootNode();
618-
}
603+
$node = $treeBuilder->getRootNode();
619604

620605
$node
621606
->useAttributeAsKey('name')
@@ -707,12 +692,7 @@ private function validateAuthenticationType(array $expected, array $actual, $aut
707692
private function createCachePluginNode()
708693
{
709694
$builder = new TreeBuilder('config');
710-
// Keep compatibility with symfony/config < 4.2
711-
if (!method_exists($builder, 'getRootNode')) {
712-
$config = $builder->root('config');
713-
} else {
714-
$config = $builder->getRootNode();
715-
}
695+
$config = $builder->getRootNode();
716696

717697
$config
718698
->fixXmlConfig('method')
@@ -805,12 +785,7 @@ private function createCachePluginNode()
805785
;
806786

807787
$treeBuilder = new TreeBuilder('cache');
808-
// Keep compatibility with symfony/config < 4.2
809-
if (!method_exists($treeBuilder, 'getRootNode')) {
810-
$cache = $treeBuilder->root('cache');
811-
} else {
812-
$cache = $treeBuilder->getRootNode();
813-
}
788+
$cache = $treeBuilder->getRootNode();
814789

815790
$cache
816791
->canBeEnabled()

src/DependencyInjection/HttplugExtension.php

+7-27
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
use Http\Mock\Client as MockClient;
2424
use Psr\Http\Client\ClientInterface;
2525
use Psr\Http\Message\UriInterface;
26+
use Symfony\Component\Config\Definition\ConfigurationInterface;
2627
use Symfony\Component\Config\FileLocator;
2728
use Symfony\Component\DependencyInjection\Alias;
2829
use Symfony\Component\DependencyInjection\ChildDefinition;
2930
use Symfony\Component\DependencyInjection\ContainerBuilder;
3031
use Symfony\Component\DependencyInjection\Definition;
31-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
3232
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3333
use Symfony\Component\DependencyInjection\Reference;
3434
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -382,14 +382,8 @@ private function configureClient(ContainerBuilder $container, $clientName, array
382382
{
383383
$serviceId = 'httplug.client.'.$clientName;
384384

385-
if (method_exists($container, 'registerAliasForArgument')) {
386-
$alias = $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
387-
388-
$interfaces = class_implements(HttpClient::class) ?? [];
389-
if (isset($interfaces[ClientInterface::class])) {
390-
$container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName);
391-
}
392-
}
385+
$container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
386+
$container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName);
393387

394388
$plugins = [];
395389
foreach ($arguments['plugins'] as $plugin) {
@@ -530,7 +524,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
530524
/**
531525
* {@inheritdoc}
532526
*/
533-
public function getConfiguration(array $config, ContainerBuilder $container)
527+
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
534528
{
535529
return new Configuration($container->getParameter('kernel.debug'));
536530
}
@@ -547,7 +541,7 @@ private function configurePlugin(ContainerBuilder $container, $serviceId, $plugi
547541
{
548542
$pluginServiceId = $serviceId.'.plugin.'.$pluginName;
549543

550-
$definition = $this->createChildDefinition('httplug.plugin.'.$pluginName);
544+
$definition = new ChildDefinition('httplug.plugin.'.$pluginName);
551545

552546
$this->configurePluginByName($pluginName, $definition, $pluginConfig, $container, $pluginServiceId);
553547
$container->setDefinition($pluginServiceId, $definition);
@@ -564,7 +558,7 @@ private function configureVcrPlugin(ContainerBuilder $container, array $config,
564558
$recordId = $prefix.'.record';
565559

566560
if ('filesystem' === $recorder) {
567-
$recorderDefinition = $this->createChildDefinition('httplug.plugin.vcr.recorder.filesystem');
561+
$recorderDefinition = new ChildDefinition('httplug.plugin.vcr.recorder.filesystem');
568562
$recorderDefinition->replaceArgument(0, $config['fixtures_directory']);
569563
$recorderId = $prefix.'.recorder';
570564

@@ -573,7 +567,7 @@ private function configureVcrPlugin(ContainerBuilder $container, array $config,
573567

574568
if ('default' === $config['naming_strategy']) {
575569
$namingStrategyId = $prefix.'.naming_strategy';
576-
$namingStrategy = $this->createChildDefinition('httplug.plugin.vcr.naming_strategy.path');
570+
$namingStrategy = new ChildDefinition('httplug.plugin.vcr.naming_strategy.path');
577571

578572
if (!empty($config['naming_strategy_options'])) {
579573
$namingStrategy->setArguments([$config['naming_strategy_options']]);
@@ -610,18 +604,4 @@ private function configureVcrPlugin(ContainerBuilder $container, array $config,
610604

611605
return $plugins;
612606
}
613-
614-
/**
615-
* BC for old Symfony versions. Remove this method and use new ChildDefinition directly when we drop support for Symfony 2.
616-
*
617-
* @param string $parent the parent service id
618-
*
619-
* @return ChildDefinition|DefinitionDecorator
620-
*/
621-
private function createChildDefinition($parent)
622-
{
623-
$definitionClass = class_exists(ChildDefinition::class) ? ChildDefinition::class : DefinitionDecorator::class;
624-
625-
return new $definitionClass($parent);
626-
}
627607
}

src/Discovery/ConfiguredClientsStrategyListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function onEvent()
2525
*
2626
* {@inheritdoc}
2727
*/
28-
public static function getSubscribedEvents()
28+
public static function getSubscribedEvents(): array
2929
{
3030
return [
3131
'kernel.request' => ['onEvent', 1024],

src/Resources/config/services.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<factory class="Http\Discovery\HttpAsyncClientDiscovery" method="find" />
2222
</service>
2323

24-
<!-- Discovery with autowiring support for Symfony 3.3+ -->
24+
<!-- Discovery with autowiring support -->
2525
<service id="httplug.message_factory.default" class="Http\Message\MessageFactory">
2626
<factory class="Http\Discovery\MessageFactoryDiscovery" method="find" />
2727
</service>

tests/Functional/ServiceInstantiationTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\HttpKernel\HttpKernelInterface;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelEvents;
27+
use Symfony\Component\HttpKernel\KernelInterface;
2728
use Symfony\Component\HttpKernel\Profiler\Profiler;
2829

2930
class ServiceInstantiationTest extends WebTestCase
@@ -125,7 +126,7 @@ public function testProfilingPsr18Decoration(): void
125126
/**
126127
* {@inheritdoc}
127128
*/
128-
protected static function bootKernel(array $options = [])
129+
protected static function bootKernel(array $options = []): KernelInterface
129130
{
130131
parent::bootKernel($options);
131132

@@ -135,11 +136,7 @@ protected static function bootKernel(array $options = [])
135136
$class = (Kernel::MAJOR_VERSION >= 5) ? RequestEvent::class : GetResponseEvent::class;
136137
$event = new $class(static::$kernel, SymfonyRequest::create('/'), HttpKernelInterface::MASTER_REQUEST);
137138

138-
if (version_compare(Kernel::VERSION, '4.3.0', '>=')) {
139-
$dispatcher->dispatch($event, KernelEvents::REQUEST);
140-
} else {
141-
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
142-
}
139+
$dispatcher->dispatch($event, KernelEvents::REQUEST);
143140

144141
return static::$kernel;
145142
}

0 commit comments

Comments
 (0)