Skip to content

Add Symfony 6 support #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ jobs:
symfony-deprecations-helper: "weak"

# Test maintained versions of Symfony
- dependencies: "php-http/guzzle6-adapter"
symfony-require: "3.4.*"
php-version: "7.3"
symfony-deprecations-helper: "weak"
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^4.4"
symfony-require: "4.4.*"
php-version: "7.3"
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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

# 1.24.1 - TBD
- Fixed deprecation notice in PHP 8.1 by adding `= null` to `\Http\HttplugBundle\Collector\Twig\HttpMessageMarkupExtension`
-
# 1.25.0 - TBD
- Added PHP 8.1 support
- Added Symfony 6 support
- Removed Symfony 3.x support

# 1.24.0 - 2021-10-23
- Changed stopwatch category from default to "httplug", so it's more prominent on Execution timeline view
- Changed tab texts inside profiler so that it shows ports in URL in case it's non-standard
Expand Down
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
"php": "^7.3 || ^8.0",
"php-http/client-common": "^1.9 || ^2.0",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.0",
"php-http/discovery": "^1.14",
"php-http/httplug": "^1.0 || ^2.0",
"php-http/logger-plugin": "^1.1",
"php-http/message": "^1.4",
"php-http/message-factory": "^1.0.2",
"php-http/stopwatch-plugin": "^1.2",
"psr/http-message": "^1.0",
"symfony/config": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/dependency-injection": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/event-dispatcher": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/http-kernel": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/options-resolver": "^3.4.34 || ^4.2.12 || ^5.0"
"symfony/config": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0"
},
"conflict": {
"php-http/guzzle6-adapter": "<1.1",
Expand All @@ -53,16 +53,15 @@
"php-http/cache-plugin": "^1.7",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/cache": "^3.4.35 || ~4.2.12 || ^4.3.8 || ^5.0",
"symfony/dom-crawler": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/framework-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/http-foundation": "^3.4.35 || ~4.2.12 || ^4.3.8 || ^5.0",
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.4.19 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.3",
"symfony/stopwatch": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/twig-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/web-profiler-bundle": "^3.4.34 || ^4.2.12 || ^5.0",
"symfony/stopwatch": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/web-profiler-bundle": "^4.4.19 || ^5.0 || ^6.0",
"twig/twig": "^1.41 || ^2.10 || ^3.0"
},
"suggest": {
Expand Down Expand Up @@ -95,7 +94,7 @@
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-stable": false,
"scripts": {
"test": "vendor/bin/simple-phpunit",
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function reset()
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'httplug';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/PluginClientFactoryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function onEvent(PluginClientFactoryListenerEventClass $e)
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
'kernel.request' => ['onEvent', 1024],
Expand Down
37 changes: 6 additions & 31 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,10 @@ public function __construct($debug)
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('httplug');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('httplug');
} else {
$rootNode = $treeBuilder->getRootNode();
}
$rootNode = $treeBuilder->getRootNode();

$this->configureClients($rootNode);
$this->configureSharedPlugins($rootNode);
Expand Down Expand Up @@ -274,12 +269,7 @@ private function configureSharedPlugins(ArrayNodeDefinition $root)
private function createClientPluginNode()
{
$treeBuilder = new TreeBuilder('plugins');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$node = $treeBuilder->root('plugins');
} else {
$node = $treeBuilder->getRootNode();
}
$node = $treeBuilder->getRootNode();

/** @var ArrayNodeDefinition $pluginList */
$pluginList = $node
Expand Down Expand Up @@ -610,12 +600,7 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA
private function createAuthenticationPluginNode()
{
$treeBuilder = new TreeBuilder('authentication');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$node = $treeBuilder->root('authentication');
} else {
$node = $treeBuilder->getRootNode();
}
$node = $treeBuilder->getRootNode();

$node
->useAttributeAsKey('name')
Expand Down Expand Up @@ -707,12 +692,7 @@ private function validateAuthenticationType(array $expected, array $actual, $aut
private function createCachePluginNode()
{
$builder = new TreeBuilder('config');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($builder, 'getRootNode')) {
$config = $builder->root('config');
} else {
$config = $builder->getRootNode();
}
$config = $builder->getRootNode();

$config
->fixXmlConfig('method')
Expand Down Expand Up @@ -805,12 +785,7 @@ private function createCachePluginNode()
;

$treeBuilder = new TreeBuilder('cache');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$cache = $treeBuilder->root('cache');
} else {
$cache = $treeBuilder->getRootNode();
}
$cache = $treeBuilder->getRootNode();

$cache
->canBeEnabled()
Expand Down
34 changes: 7 additions & 27 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use Http\Mock\Client as MockClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\UriInterface;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -382,14 +382,8 @@ private function configureClient(ContainerBuilder $container, $clientName, array
{
$serviceId = 'httplug.client.'.$clientName;

if (method_exists($container, 'registerAliasForArgument')) {
$alias = $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);

$interfaces = class_implements(HttpClient::class) ?? [];
if (isset($interfaces[ClientInterface::class])) {
$container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName);
}
}
$container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
$container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName);

$plugins = [];
foreach ($arguments['plugins'] as $plugin) {
Expand Down Expand Up @@ -530,7 +524,7 @@ private function configureAutoDiscoveryClients(ContainerBuilder $container, arra
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
return new Configuration($container->getParameter('kernel.debug'));
}
Expand All @@ -547,7 +541,7 @@ private function configurePlugin(ContainerBuilder $container, $serviceId, $plugi
{
$pluginServiceId = $serviceId.'.plugin.'.$pluginName;

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

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

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

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

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

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

return $plugins;
}

/**
* BC for old Symfony versions. Remove this method and use new ChildDefinition directly when we drop support for Symfony 2.
*
* @param string $parent the parent service id
*
* @return ChildDefinition|DefinitionDecorator
*/
private function createChildDefinition($parent)
{
$definitionClass = class_exists(ChildDefinition::class) ? ChildDefinition::class : DefinitionDecorator::class;

return new $definitionClass($parent);
}
}
2 changes: 1 addition & 1 deletion src/Discovery/ConfiguredClientsStrategyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function onEvent()
*
* {@inheritdoc}
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
'kernel.request' => ['onEvent', 1024],
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<factory class="Http\Discovery\HttpAsyncClientDiscovery" method="find" />
</service>

<!-- Discovery with autowiring support for Symfony 3.3+ -->
<!-- Discovery with autowiring support -->
<service id="httplug.message_factory.default" class="Http\Message\MessageFactory">
<factory class="Http\Discovery\MessageFactoryDiscovery" method="find" />
</service>
Expand Down
9 changes: 3 additions & 6 deletions tests/Functional/ServiceInstantiationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Profiler\Profiler;

class ServiceInstantiationTest extends WebTestCase
Expand Down Expand Up @@ -125,7 +126,7 @@ public function testProfilingPsr18Decoration(): void
/**
* {@inheritdoc}
*/
protected static function bootKernel(array $options = [])
protected static function bootKernel(array $options = []): KernelInterface
{
parent::bootKernel($options);

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

if (version_compare(Kernel::VERSION, '4.3.0', '>=')) {
$dispatcher->dispatch($event, KernelEvents::REQUEST);
} else {
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
}
$dispatcher->dispatch($event, KernelEvents::REQUEST);

return static::$kernel;
}
Expand Down
Loading