Skip to content

Commit

Permalink
Merge pull request #472 from php-http/remove-deprecated-code
Browse files Browse the repository at this point in the history
remove all deprecated code
  • Loading branch information
dbu authored Sep 10, 2024
2 parents b621fbd + a561ace commit 2b25608
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 226 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
# 2.0.0 - (unreleased)

- Increased min PHP version to 8.1
- Removed the deprecated `httplug_markup` twig filter. Use `@Httplug/http_message.html.twig` template instead.
- Removed deprecated configuration options:
- `toolbar`: Use `profiling` instead.
- `respect_cache_headers`: Use `respect_response_cache_directives` instead.
- Removed the deprecated `Http\HttplugBundle\ClientFactory\PluginClientFactory`. Use `Http\Client\Common\PluginClientFactory` instead.
- Fixed a deprecation when creating a `HttpMethodsClient` via `http_methods_client: true`. Only PSR-17 factories are now passed as constructor arguments.
- Changed the default stream factory argument for the cache plugin. This now requires a PSR-17 StreamFactoryInterface instance.
Expand Down
35 changes: 5 additions & 30 deletions src/Collector/Twig/HttpMessageMarkupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,17 @@ public function __construct(?ClonerInterface $cloner = null, ?DataDumperInterfac
public function getFilters(): array
{
return [
new TwigFilter('httplug_markup', $this->markup(...), ['is_safe' => ['html']]),
new TwigFilter('httplug_markup_body', $this->markupBody(...), ['is_safe' => ['html']]),
];
}

/**
* @param string $message http message
*/
public function markup($message)
{
@trigger_error('"httplug_markup" twig extension is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.', E_USER_DEPRECATED);

$safeMessage = htmlentities($message);
$parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);

if (!isset($parts[1])) {
// This is not a HTTP message
return $safeMessage;
}

if (empty($parts[1])) {
$parts[1] = '(This message has no captured body)';
}

// make header names bold
$headers = preg_replace("|\n(.*?): |si", "\n<b>$1</b>: ", $parts[0]);

return sprintf("%s\n\n<div class='httplug-http-body httplug-hidden'>%s</div>", $headers, $parts[1]);
}

public function markupBody(string $body): ?string
{
if (in_array(substr($body, 0, 1), ['{', '['], true)) {
$json = json_decode($body, true);
if (JSON_ERROR_NONE === json_last_error()) {
$body = $json;
if ('' !== $body && in_array($body[0], ['{', '['], true)) {
try {
$body = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException) {
// ignore
}
}

Expand Down
41 changes: 0 additions & 41 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,6 @@ public function getConfigTreeBuilder(): TreeBuilder
return $v;
})
->end()
->beforeNormalization()
->ifTrue(fn ($v) => is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']))
->then(function ($v) {
if (array_key_exists('profiling', $v)) {
throw new InvalidConfigurationException('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".');
}

@trigger_error('"httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use "httplug.profiling" instead.', E_USER_DEPRECATED);

if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) {
@trigger_error('"auto" value in "httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use a boolean value instead.', E_USER_DEPRECATED);
$v['toolbar']['enabled'] = $this->debug;
}

$v['profiling'] = $v['toolbar'];

unset($v['toolbar']);

return $v;
})
->end()
->fixXmlConfig('client')
->children()
->booleanNode('default_client_autowiring')
Expand Down Expand Up @@ -718,12 +697,6 @@ private function createCachePluginNode(): NodeDefinition
->fixXmlConfig('respect_response_cache_directive')
->fixXmlConfig('cache_listener')
->addDefaultsIfNotSet()
->validate()
->ifTrue(fn ($config) =>
// Cannot set both respect_cache_headers and respect_response_cache_directives
isset($config['respect_cache_headers'], $config['respect_response_cache_directives']))
->thenInvalid('You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaneously. Use "respect_response_cache_directives" instead.')
->end()
->children()
->scalarNode('cache_key_generator')
->info('This must be a service id to a service implementing '.CacheKeyGenerator::class)
Expand Down Expand Up @@ -778,20 +751,6 @@ private function createCachePluginNode(): NodeDefinition
->prototype('scalar')
->end()
->end()
->scalarNode('respect_cache_headers')
->info('Whether we should care about cache headers or not [DEPRECATED]')
->beforeNormalization()
->always(function ($v) {
@trigger_error('The option "respect_cache_headers" is deprecated since version 1.3 and will be removed in 2.0. Use "respect_response_cache_directives" instead.', E_USER_DEPRECATED);

return $v;
})
->end()
->validate()
->ifNotInArray([null, true, false])
->thenInvalid('Value for "respect_cache_headers" must be null or boolean')
->end()
->end()
->variableNode('respect_response_cache_directives')
->info('A list of cache directives to respect when caching responses. Omit or set to null to respect the default set of directives.')
->validate()
Expand Down
6 changes: 0 additions & 6 deletions tests/Resources/Fixtures/config/bc/cache_config.yml

This file was deleted.

6 changes: 0 additions & 6 deletions tests/Resources/Fixtures/config/bc/issue-166.yml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/Resources/Fixtures/config/bc/profiling_toolbar.yml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/Resources/Fixtures/config/bc/toolbar.yml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Resources/Fixtures/config/bc/toolbar_auto.yml

This file was deleted.

9 changes: 0 additions & 9 deletions tests/Resources/Fixtures/config/invalid_cache_config.yml

This file was deleted.

76 changes: 0 additions & 76 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,82 +350,6 @@ public function testInvalidAuthentication(): void
$this->assertProcessedConfigurationEquals([], [$file]);
}

/**
* @group legacy
*/
public function testInvalidCacheConfig(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_cache_config.yml';

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "httplug.plugins.cache.config": You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaneously. Use "respect_response_cache_directives" instead.');
$this->assertProcessedConfigurationEquals([], [$file]);
}

/**
* @group legacy
*/
public function testBackwardCompatibility(): void
{
$formats = array_map(fn ($path) => __DIR__.'/../../Resources/Fixtures/'.$path, [
'config/bc/toolbar.yml',
'config/bc/toolbar_auto.yml',
]);

foreach ($formats as $format) {
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
}
}

/**
* @group legacy
*/
public function testCacheConfigDeprecationCompatibility(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/bc/cache_config.yml';
$config = $this->emptyConfig;
$config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
'enabled' => true,
'cache_pool' => 'my_cache_pool',
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => true,
'blacklisted_paths' => [],
'cache_listeners' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);
}

/**
* @group legacy
*/
public function testCacheConfigDeprecationCompatibilityIssue166(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/bc/issue-166.yml';
$config = $this->emptyConfig;
$config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
'enabled' => true,
'cache_pool' => 'my_cache_pool',
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => false,
'blacklisted_paths' => [],
'cache_listeners' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);
}

public function testProfilingToolbarCollision(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml';

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".');
$this->assertProcessedConfigurationEquals([], [$file]);
}

public function testClientCacheConfigMustHavePool(): void
{
$file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml';
Expand Down
46 changes: 0 additions & 46 deletions tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Http\Adapter\Guzzle7\Client;
use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder;
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Psr\Http\Client\ClientInterface;
Expand Down Expand Up @@ -204,28 +203,6 @@ public function testClientPlugins(): void
$this->assertContainerBuilderHasService('httplug.client.mock');
}

/**
* @group legacy
*/
public function testNoProfilingWhenToolbarIsDisabled(): void
{
$this->load(
[
'toolbar' => [
'enabled' => false,
],
'clients' => [
'acme' => [
'factory' => 'httplug.factory.curl',
'plugins' => ['foo'],
],
],
]
);

$this->verifyProfilingDisabled();
}

public function testNoProfilingWhenNotInDebugMode(): void
{
$this->setParameter('kernel.debug', false);
Expand All @@ -243,29 +220,6 @@ public function testNoProfilingWhenNotInDebugMode(): void
$this->verifyProfilingDisabled();
}

/**
* @group legacy
*/
public function testProfilingWhenToolbarIsSpecificallyOn(): void
{
$this->setParameter('kernel.debug', false);
$this->load(
[
'toolbar' => [
'enabled' => true,
],
'clients' => [
'acme' => [
'factory' => 'httplug.factory.curl',
'plugins' => ['foo'],
],
],
]
);

$this->assertContainerBuilderHasService(PluginClientFactoryListener::class);
}

public function testOverrideProfilingFormatter(): void
{
$this->load(
Expand Down

0 comments on commit 2b25608

Please sign in to comment.