Skip to content

Commit edf5204

Browse files
committed
Add Symfony 6 support
1 parent afd8aaf commit edf5204

File tree

12 files changed

+77
-144
lines changed

12 files changed

+77
-144
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 0 additions & 4 deletions
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 15 additions & 16 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 31 deletions
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
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;
@@ -530,7 +531,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
530531
/**
531532
* {@inheritdoc}
532533
*/
533-
public function getConfiguration(array $config, ContainerBuilder $container)
534+
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
534535
{
535536
return new Configuration($container->getParameter('kernel.debug'));
536537
}

src/Discovery/ConfiguredClientsStrategyListener.php

Lines changed: 1 addition & 1 deletion
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],

tests/Functional/ServiceInstantiationTest.php

Lines changed: 3 additions & 6 deletions
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
}

tests/Resources/app/AppKernel.php

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
declare(strict_types=1);
44

5-
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
65
use Symfony\Component\Config\Loader\LoaderInterface;
76
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
87
use Symfony\Component\DependencyInjection\ContainerBuilder;
98
use Symfony\Component\HttpFoundation\Response;
109
use Symfony\Component\HttpKernel\Kernel;
11-
use Symfony\Component\Routing\RouteCollectionBuilder;
10+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
11+
use Symfony\Component\Routing\Loader\PhpFileLoader as RoutingPhpFileLoader;
12+
use Symfony\Component\Routing\Route;
13+
use Symfony\Component\Routing\RouteCollection;
1214

1315
class AppKernel extends Kernel
1416
{
15-
use MicroKernelTrait;
16-
1717
/**
1818
* @var string
1919
*/
@@ -22,7 +22,7 @@ class AppKernel extends Kernel
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function registerBundles()
25+
public function registerBundles(): iterable
2626
{
2727
$bundles = [
2828
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
@@ -37,37 +37,52 @@ public function registerBundles()
3737
return $bundles;
3838
}
3939

40-
/**
41-
* {@inheritdoc}
42-
*/
43-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
40+
public function registerContainerConfiguration(LoaderInterface $loader)
4441
{
45-
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
46-
if ($this->isDebug()) {
47-
$loader->load(__DIR__.'/config/config_debug.yml');
48-
}
42+
$loader->load(function (ContainerBuilder $container) use ($loader) {
43+
$container->loadFromExtension('framework', [
44+
'router' => [
45+
'resource' => 'kernel::loadRoutes',
46+
'type' => 'service',
47+
'utf8' => true,
48+
],
49+
]);
50+
51+
$container->register('kernel', static::class)
52+
->addTag('routing.route_loader')
53+
->setAutoconfigured(true)
54+
->setSynthetic(true)
55+
->setPublic(true)
56+
;
57+
58+
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
59+
if ($this->isDebug()) {
60+
$loader->load(__DIR__.'/config/config_debug.yml');
61+
}
62+
});
4963
}
5064

51-
/**
52-
* {@inheritdoc}
53-
*/
54-
protected function configureRoutes(RouteCollectionBuilder $routes): void
65+
public function loadRoutes(LoaderInterface $loader): RouteCollection
5566
{
56-
$routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt');
57-
$routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler');
58-
59-
if (Kernel::MAJOR_VERSION < 4 || (Kernel::MAJOR_VERSION === 4 && Kernel::MINOR_VERSION === 0)) {
60-
$routes->add('/', 'kernel:indexAction');
61-
} else {
62-
// If 4.1+
63-
$routes->add('/', 'kernel::indexAction');
64-
}
67+
$file = (new \ReflectionObject($this))->getFileName();
68+
/* @var RoutingPhpFileLoader $kernelLoader */
69+
$kernelLoader = $loader->getResolver()->resolve($file, 'php');
70+
$kernelLoader->setCurrentDir(\dirname($file));
71+
72+
$collection = new RouteCollection();
73+
$collection->add('/', new Route('/', ['_controller' => 'kernel::indexAction']));
74+
75+
$routes = new RoutingConfigurator($collection, $kernelLoader, $file, $file);
76+
$routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml')->prefix('_wdt');
77+
$routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml')->prefix('_profiler');
78+
79+
return $collection;
6580
}
6681

6782
/**
6883
* {@inheritdoc}
6984
*/
70-
public function getCacheDir()
85+
public function getCacheDir(): string
7186
{
7287
if (null === self::$cacheDir) {
7388
self::$cacheDir = uniqid('cache');
@@ -79,19 +94,11 @@ public function getCacheDir()
7994
/**
8095
* {@inheritdoc}
8196
*/
82-
public function getLogDir()
97+
public function getLogDir(): string
8398
{
8499
return sys_get_temp_dir().'/httplug-bundle/logs';
85100
}
86101

87-
/**
88-
* {@inheritdoc}
89-
*/
90-
protected function getContainerBaseClass()
91-
{
92-
return '\PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer';
93-
}
94-
95102
public function indexAction()
96103
{
97104
return new Response();

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,6 @@ protected function getConfiguration(): ConfigurationInterface
111111
return new Configuration(true);
112112
}
113113

114-
public function testEmptyConfiguration(): void
115-
{
116-
$formats = array_map(function ($path) {
117-
return __DIR__.'/../../Resources/Fixtures/'.$path;
118-
}, [
119-
'config/empty.yml',
120-
'config/empty.xml',
121-
'config/empty.php',
122-
]);
123-
124-
foreach ($formats as $format) {
125-
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
126-
}
127-
}
128-
129114
public function testSupportsAllConfigFormats(): void
130115
{
131116
if (!class_exists(Client::class)) {

0 commit comments

Comments
 (0)