Skip to content

Commit aa7d969

Browse files
authored
Merge pull request #249 from getsentry/add-max_request_body_size-option
Add max_request_body_size option
2 parents 5b8b5de + 8ec0ee6 commit aa7d969

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- Fix Hub initialization for `ErrorListener` (#243, thanks to @teohhanhui)
1010
- Fix compatibility with sentry/sentry 2.2+ (#244)
1111
- Add support for `class_serializers` option (#245)
12+
- Add support for `max_request_body_size` option (#249)
1213

1314
## 3.1.0 - 2019-07-02
1415
- Add support for Symfony 2.8 (#233, thanks to @nocive)

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ parameters:
66
ignoreErrors:
77
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
88
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
9+
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
10+
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
911
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
1012
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
1113
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'
12-
- '/Sentry\\SentrySdk/'
1314

1415
includes:
1516
- vendor/jangregor/phpstan-prophecy/src/extension.neon

src/DependencyInjection/Configuration.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function getConfigTreeBuilder(): TreeBuilder
9393
})
9494
->thenInvalid('Expecting service reference, got "%s"');
9595
$optionsChildNodes->scalarNode('logger');
96+
if ($this->maxRequestBodySizeIsSupported()) {
97+
$optionsChildNodes->enumNode('max_request_body_size')
98+
->values([
99+
'none',
100+
'small',
101+
'medium',
102+
'always',
103+
]);
104+
}
96105
$optionsChildNodes->integerNode('max_breadcrumbs')
97106
->min(1);
98107
$optionsChildNodes->integerNode('max_value_length')
@@ -171,12 +180,11 @@ private function isNotAValidCallback(): \Closure
171180

172181
private function classSerializersAreSupported(): bool
173182
{
174-
try {
175-
new Options(['class_serializers' => []]);
183+
return method_exists(Options::class, 'getClassSerializers');
184+
}
176185

177-
return true;
178-
} catch (\Throwable $throwable) {
179-
return false;
180-
}
186+
private function maxRequestBodySizeIsSupported(): bool
187+
{
188+
return method_exists(Options::class, 'getMaxRequestBodySize');
181189
}
182190
}

src/DependencyInjection/SentryExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
6767
'excluded_exceptions',
6868
'http_proxy',
6969
'logger',
70+
'max_request_body_size',
7071
'max_breadcrumbs',
7172
'max_value_length',
7273
'prefixes',

test/BaseTestCase.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sentry\Options;
7-
use Sentry\SentryBundle\Test\DependencyInjection\ConfigurationTest;
87

98
abstract class BaseTestCase extends TestCase
109
{
11-
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;
12-
1310
protected function classSerializersAreSupported(): bool
1411
{
15-
try {
16-
new Options(['class_serializers' => []]);
12+
return method_exists(Options::class, 'getClassSerializers');
13+
}
1714

18-
return true;
19-
} catch (\Throwable $throwable) {
20-
return false;
21-
}
15+
protected function maxRequestBodySizeIsSupported(): bool
16+
{
17+
return method_exists(Options::class, 'getMaxRequestBodySize');
2218
}
2319

2420
protected function getSupportedOptionsCount(): int
2521
{
22+
$count = 23;
23+
2624
if ($this->classSerializersAreSupported()) {
27-
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
25+
++$count;
26+
}
27+
28+
if ($this->maxRequestBodySizeIsSupported()) {
29+
++$count;
2830
}
2931

30-
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT;
32+
return $count;
3133
}
3234
}

test/DependencyInjection/ConfigurationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public function optionValuesProvider(): array
130130
}
131131

132132
if ($this->classSerializersAreSupported()) {
133+
$options[] = ['max_request_body_size', 'none'];
134+
$options[] = ['max_request_body_size', 'small'];
135+
$options[] = ['max_request_body_size', 'medium'];
136+
$options[] = ['max_request_body_size', 'always'];
137+
}
138+
139+
if ($this->maxRequestBodySizeIsSupported()) {
133140
$options[] = ['class_serializers', ['count']];
134141
}
135142

@@ -198,6 +205,11 @@ public function invalidValuesProvider(): array
198205
$values[] = ['class_serializers', -1];
199206
}
200207

208+
if ($this->maxRequestBodySizeIsSupported()) {
209+
$values[] = ['max_request_body_size', null];
210+
$values[] = ['max_request_body_size', 'invalid'];
211+
}
212+
201213
return $values;
202214
}
203215

test/DependencyInjection/SentryExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public function optionsValueProvider(): array
148148
];
149149
}
150150

151+
if ($this->maxRequestBodySizeIsSupported()) {
152+
$options[] = ['max_request_body_size', 'always'];
153+
}
154+
151155
return $options;
152156
}
153157

0 commit comments

Comments
 (0)