Skip to content

Commit 8f1b21e

Browse files
committed
remove all deprecated code
1 parent 4d1ca68 commit 8f1b21e

File tree

11 files changed

+6
-224
lines changed

11 files changed

+6
-224
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
66

77
# 2.0.0 - (unreleased)
88
- Increased min PHP version to 8.1
9+
- Removed the deprecated `httplug_markup` twig filter. Use `@Httplug/http_message.html.twig` template instead.
10+
- Removed deprecated configuration options:
11+
- `toolbar`: Use `profiling` instead.
12+
- `respect_cache_headers`: Use `respect_response_cache_directives` instead.
913
- Removed the deprecated `Http\HttplugBundle\ClientFactory\PluginClientFactory`. Use `Http\Client\Common\PluginClientFactory` instead.
1014
- Fixed a deprecation when creating a `HttpMethodsClient` via `http_methods_client: true`. Only PSR-17 factories are now passed as constructor arguments.
1115
- Changed the default stream factory argument for the cache plugin. This now requires a PSR-17 StreamFactoryInterface instance.

src/Collector/Twig/HttpMessageMarkupExtension.php

+2-28
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,14 @@ public function __construct(?ClonerInterface $cloner = null, ?DataDumperInterfac
3434
public function getFilters()
3535
{
3636
return [
37-
new TwigFilter('httplug_markup', $this->markup(...), ['is_safe' => ['html']]),
3837
new TwigFilter('httplug_markup_body', $this->markupBody(...), ['is_safe' => ['html']]),
3938
];
4039
}
4140

42-
/**
43-
* @param string $message http message
44-
*/
45-
public function markup($message)
46-
{
47-
@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);
48-
49-
$safeMessage = htmlentities($message);
50-
$parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);
51-
52-
if (!isset($parts[1])) {
53-
// This is not a HTTP message
54-
return $safeMessage;
55-
}
56-
57-
if (empty($parts[1])) {
58-
$parts[1] = '(This message has no captured body)';
59-
}
60-
61-
// make header names bold
62-
$headers = preg_replace("|\n(.*?): |si", "\n<b>$1</b>: ", $parts[0]);
63-
64-
return sprintf("%s\n\n<div class='httplug-http-body httplug-hidden'>%s</div>", $headers, $parts[1]);
65-
}
66-
6741
public function markupBody(string $body): ?string
6842
{
69-
if (in_array(substr($body, 0, 1), ['{', '['], true)) {
70-
$json = json_decode($body, true);
43+
if ('' !== $body && in_array($body[0], ['{', '['], true)) {
44+
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
7145
if (JSON_ERROR_NONE === json_last_error()) {
7246
$body = $json;
7347
}

src/DependencyInjection/Configuration.php

-41
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,6 @@ public function getConfigTreeBuilder(): TreeBuilder
8080
return $v;
8181
})
8282
->end()
83-
->beforeNormalization()
84-
->ifTrue(fn ($v) => is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']))
85-
->then(function ($v) {
86-
if (array_key_exists('profiling', $v)) {
87-
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".');
88-
}
89-
90-
@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);
91-
92-
if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) {
93-
@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);
94-
$v['toolbar']['enabled'] = $this->debug;
95-
}
96-
97-
$v['profiling'] = $v['toolbar'];
98-
99-
unset($v['toolbar']);
100-
101-
return $v;
102-
})
103-
->end()
10483
->fixXmlConfig('client')
10584
->children()
10685
->booleanNode('default_client_autowiring')
@@ -725,12 +704,6 @@ private function createCachePluginNode(): NodeDefinition
725704
->fixXmlConfig('respect_response_cache_directive')
726705
->fixXmlConfig('cache_listener')
727706
->addDefaultsIfNotSet()
728-
->validate()
729-
->ifTrue(fn ($config) =>
730-
// Cannot set both respect_cache_headers and respect_response_cache_directives
731-
isset($config['respect_cache_headers'], $config['respect_response_cache_directives']))
732-
->thenInvalid('You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaneously. Use "respect_response_cache_directives" instead.')
733-
->end()
734707
->children()
735708
->scalarNode('cache_key_generator')
736709
->info('This must be a service id to a service implementing '.CacheKeyGenerator::class)
@@ -785,20 +758,6 @@ private function createCachePluginNode(): NodeDefinition
785758
->prototype('scalar')
786759
->end()
787760
->end()
788-
->scalarNode('respect_cache_headers')
789-
->info('Whether we should care about cache headers or not [DEPRECATED]')
790-
->beforeNormalization()
791-
->always(function ($v) {
792-
@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);
793-
794-
return $v;
795-
})
796-
->end()
797-
->validate()
798-
->ifNotInArray([null, true, false])
799-
->thenInvalid('Value for "respect_cache_headers" must be null or boolean')
800-
->end()
801-
->end()
802761
->variableNode('respect_response_cache_directives')
803762
->info('A list of cache directives to respect when caching responses. Omit or set to null to respect the default set of directives.')
804763
->validate()

tests/Resources/Fixtures/config/bc/cache_config.yml

-6
This file was deleted.

tests/Resources/Fixtures/config/bc/issue-166.yml

-6
This file was deleted.

tests/Resources/Fixtures/config/bc/profiling_toolbar.yml

-4
This file was deleted.

tests/Resources/Fixtures/config/bc/toolbar.yml

-5
This file was deleted.

tests/Resources/Fixtures/config/bc/toolbar_auto.yml

-3
This file was deleted.

tests/Resources/Fixtures/config/invalid_cache_config.yml

-9
This file was deleted.

tests/Unit/DependencyInjection/ConfigurationTest.php

-76
Original file line numberDiff line numberDiff line change
@@ -350,82 +350,6 @@ public function testInvalidAuthentication(): void
350350
$this->assertProcessedConfigurationEquals([], [$file]);
351351
}
352352

353-
/**
354-
* @group legacy
355-
*/
356-
public function testInvalidCacheConfig(): void
357-
{
358-
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_cache_config.yml';
359-
360-
$this->expectException(InvalidConfigurationException::class);
361-
$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.');
362-
$this->assertProcessedConfigurationEquals([], [$file]);
363-
}
364-
365-
/**
366-
* @group legacy
367-
*/
368-
public function testBackwardCompatibility(): void
369-
{
370-
$formats = array_map(fn ($path) => __DIR__.'/../../Resources/Fixtures/'.$path, [
371-
'config/bc/toolbar.yml',
372-
'config/bc/toolbar_auto.yml',
373-
]);
374-
375-
foreach ($formats as $format) {
376-
$this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
377-
}
378-
}
379-
380-
/**
381-
* @group legacy
382-
*/
383-
public function testCacheConfigDeprecationCompatibility(): void
384-
{
385-
$file = __DIR__.'/../../Resources/Fixtures/config/bc/cache_config.yml';
386-
$config = $this->emptyConfig;
387-
$config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
388-
'enabled' => true,
389-
'cache_pool' => 'my_cache_pool',
390-
'config' => [
391-
'methods' => ['GET', 'HEAD'],
392-
'respect_cache_headers' => true,
393-
'blacklisted_paths' => [],
394-
'cache_listeners' => [],
395-
],
396-
]);
397-
$this->assertProcessedConfigurationEquals($config, [$file]);
398-
}
399-
400-
/**
401-
* @group legacy
402-
*/
403-
public function testCacheConfigDeprecationCompatibilityIssue166(): void
404-
{
405-
$file = __DIR__.'/../../Resources/Fixtures/config/bc/issue-166.yml';
406-
$config = $this->emptyConfig;
407-
$config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
408-
'enabled' => true,
409-
'cache_pool' => 'my_cache_pool',
410-
'config' => [
411-
'methods' => ['GET', 'HEAD'],
412-
'respect_cache_headers' => false,
413-
'blacklisted_paths' => [],
414-
'cache_listeners' => [],
415-
],
416-
]);
417-
$this->assertProcessedConfigurationEquals($config, [$file]);
418-
}
419-
420-
public function testProfilingToolbarCollision(): void
421-
{
422-
$file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml';
423-
424-
$this->expectException(InvalidConfigurationException::class);
425-
$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".');
426-
$this->assertProcessedConfigurationEquals([], [$file]);
427-
}
428-
429353
public function testClientCacheConfigMustHavePool(): void
430354
{
431355
$file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml';

tests/Unit/DependencyInjection/HttplugExtensionTest.php

-46
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Http\Adapter\Guzzle7\Client;
88
use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder;
9-
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
109
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
1110
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
1211
use Psr\Http\Client\ClientInterface;
@@ -204,28 +203,6 @@ public function testClientPlugins(): void
204203
$this->assertContainerBuilderHasService('httplug.client.mock');
205204
}
206205

207-
/**
208-
* @group legacy
209-
*/
210-
public function testNoProfilingWhenToolbarIsDisabled(): void
211-
{
212-
$this->load(
213-
[
214-
'toolbar' => [
215-
'enabled' => false,
216-
],
217-
'clients' => [
218-
'acme' => [
219-
'factory' => 'httplug.factory.curl',
220-
'plugins' => ['foo'],
221-
],
222-
],
223-
]
224-
);
225-
226-
$this->verifyProfilingDisabled();
227-
}
228-
229206
public function testNoProfilingWhenNotInDebugMode(): void
230207
{
231208
$this->setParameter('kernel.debug', false);
@@ -243,29 +220,6 @@ public function testNoProfilingWhenNotInDebugMode(): void
243220
$this->verifyProfilingDisabled();
244221
}
245222

246-
/**
247-
* @group legacy
248-
*/
249-
public function testProfilingWhenToolbarIsSpecificallyOn(): void
250-
{
251-
$this->setParameter('kernel.debug', false);
252-
$this->load(
253-
[
254-
'toolbar' => [
255-
'enabled' => true,
256-
],
257-
'clients' => [
258-
'acme' => [
259-
'factory' => 'httplug.factory.curl',
260-
'plugins' => ['foo'],
261-
],
262-
],
263-
]
264-
);
265-
266-
$this->assertContainerBuilderHasService(PluginClientFactoryListener::class);
267-
}
268-
269223
public function testOverrideProfilingFormatter(): void
270224
{
271225
$this->load(

0 commit comments

Comments
 (0)