Skip to content

Commit a561ace

Browse files
committed
remove all deprecated code
1 parent b621fbd commit a561ace

File tree

11 files changed

+9
-226
lines changed

11 files changed

+9
-226
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
77
# 2.0.0 - (unreleased)
88

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

src/Collector/Twig/HttpMessageMarkupExtension.php

+5-30
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,17 @@ public function __construct(?ClonerInterface $cloner = null, ?DataDumperInterfac
3232
public function getFilters(): array
3333
{
3434
return [
35-
new TwigFilter('httplug_markup', $this->markup(...), ['is_safe' => ['html']]),
3635
new TwigFilter('httplug_markup_body', $this->markupBody(...), ['is_safe' => ['html']]),
3736
];
3837
}
3938

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

src/DependencyInjection/Configuration.php

-41
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,6 @@ public function getConfigTreeBuilder(): TreeBuilder
7373
return $v;
7474
})
7575
->end()
76-
->beforeNormalization()
77-
->ifTrue(fn ($v) => is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']))
78-
->then(function ($v) {
79-
if (array_key_exists('profiling', $v)) {
80-
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".');
81-
}
82-
83-
@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);
84-
85-
if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) {
86-
@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);
87-
$v['toolbar']['enabled'] = $this->debug;
88-
}
89-
90-
$v['profiling'] = $v['toolbar'];
91-
92-
unset($v['toolbar']);
93-
94-
return $v;
95-
})
96-
->end()
9776
->fixXmlConfig('client')
9877
->children()
9978
->booleanNode('default_client_autowiring')
@@ -718,12 +697,6 @@ private function createCachePluginNode(): NodeDefinition
718697
->fixXmlConfig('respect_response_cache_directive')
719698
->fixXmlConfig('cache_listener')
720699
->addDefaultsIfNotSet()
721-
->validate()
722-
->ifTrue(fn ($config) =>
723-
// Cannot set both respect_cache_headers and respect_response_cache_directives
724-
isset($config['respect_cache_headers'], $config['respect_response_cache_directives']))
725-
->thenInvalid('You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaneously. Use "respect_response_cache_directives" instead.')
726-
->end()
727700
->children()
728701
->scalarNode('cache_key_generator')
729702
->info('This must be a service id to a service implementing '.CacheKeyGenerator::class)
@@ -778,20 +751,6 @@ private function createCachePluginNode(): NodeDefinition
778751
->prototype('scalar')
779752
->end()
780753
->end()
781-
->scalarNode('respect_cache_headers')
782-
->info('Whether we should care about cache headers or not [DEPRECATED]')
783-
->beforeNormalization()
784-
->always(function ($v) {
785-
@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);
786-
787-
return $v;
788-
})
789-
->end()
790-
->validate()
791-
->ifNotInArray([null, true, false])
792-
->thenInvalid('Value for "respect_cache_headers" must be null or boolean')
793-
->end()
794-
->end()
795754
->variableNode('respect_response_cache_directives')
796755
->info('A list of cache directives to respect when caching responses. Omit or set to null to respect the default set of directives.')
797756
->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)