Skip to content

Commit 0da53b0

Browse files
authored
ref: replace symfony options resolver with custom resolver (#1914)
1 parent e3933fa commit 0da53b0

File tree

8 files changed

+782
-336
lines changed

8 files changed

+782
-336
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"ext-mbstring": "*",
2828
"ext-curl": "*",
2929
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
30-
"psr/log": "^1.0|^2.0|^3.0",
31-
"symfony/options-resolver": "^4.4.30|^5.0.11|^6.0|^7.0"
30+
"psr/log": "^1.0|^2.0|^3.0"
3231
},
3332
"require-dev": {
3433
"friendsofphp/php-cs-fixer": "^3.4",

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ parameters:
2828
count: 1
2929
path: src/Dsn.php
3030

31-
-
32-
message: "#^Property Sentry\\\\Integration\\\\RequestIntegration\\:\\:\\$options \\(array\\{pii_sanitize_headers\\: array\\<string\\>\\}\\) does not accept array\\.$#"
33-
count: 1
34-
path: src/Integration/RequestIntegration.php
35-
3631
-
3732
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
3833
count: 1

src/Integration/RequestIntegration.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
use Sentry\Event;
1010
use Sentry\Exception\JsonException;
1111
use Sentry\Options;
12+
use Sentry\OptionsResolver;
1213
use Sentry\SentrySdk;
1314
use Sentry\State\Scope;
1415
use Sentry\UserDataBag;
1516
use Sentry\Util\JSON;
16-
use Symfony\Component\OptionsResolver\Options as SymfonyOptions;
17-
use Symfony\Component\OptionsResolver\OptionsResolver;
1817

1918
/**
2019
* This integration collects information from the request and attaches them to
@@ -68,10 +67,6 @@ final class RequestIntegration implements IntegrationInterface
6867

6968
/**
7069
* @var array<string, mixed> The options
71-
*
72-
* @psalm-var array{
73-
* pii_sanitize_headers: string[]
74-
* }
7570
*/
7671
private $options;
7772

@@ -80,10 +75,6 @@ final class RequestIntegration implements IntegrationInterface
8075
*
8176
* @param RequestFetcherInterface|null $requestFetcher PSR-7 request fetcher
8277
* @param array<string, mixed> $options The options
83-
*
84-
* @psalm-param array{
85-
* pii_sanitize_headers?: string[]
86-
* } $options
8778
*/
8879
public function __construct(?RequestFetcherInterface $requestFetcher = null, array $options = [])
8980
{
@@ -178,6 +169,10 @@ private function sanitizeHeaders(array $headers): array
178169
// Cast the header name into a string, to avoid errors on numeric headers
179170
$name = (string) $name;
180171

172+
if (!\is_array($this->options['pii_sanitize_headers'])) {
173+
break;
174+
}
175+
181176
if (!\in_array(strtolower($name), $this->options['pii_sanitize_headers'], true)) {
182177
continue;
183178
}
@@ -302,10 +297,10 @@ private function isRequestBodySizeWithinReadBounds(int $requestBodySize, string
302297
*/
303298
private function configureOptions(OptionsResolver $resolver): void
304299
{
305-
$resolver->setDefault('pii_sanitize_headers', self::DEFAULT_SENSITIVE_HEADERS);
306300
$resolver->setAllowedTypes('pii_sanitize_headers', 'string[]');
307-
$resolver->setNormalizer('pii_sanitize_headers', static function (SymfonyOptions $options, array $value): array {
301+
$resolver->setNormalizer('pii_sanitize_headers', static function (array $value): array {
308302
return array_map('strtolower', $value);
309303
});
304+
$resolver->setDefault('pii_sanitize_headers', self::DEFAULT_SENSITIVE_HEADERS);
310305
}
311306
}

0 commit comments

Comments
 (0)