Skip to content

Add max_request_body_size option #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix Hub initialization for `ErrorListener` (#243, thanks to @teohhanhui)
- Fix compatibility with sentry/sentry 2.2+ (#244)
- Add support for `class_serializers` option (#245)
- Add support for `max_request_body_size` option (#249)

## 3.1.0 - 2019-07-02
- Add support for Symfony 2.8 (#233, thanks to @nocive)
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ parameters:
ignoreErrors:
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'
- '/Sentry\\SentrySdk/'

includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
Expand Down
20 changes: 14 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public function getConfigTreeBuilder(): TreeBuilder
})
->thenInvalid('Expecting service reference, got "%s"');
$optionsChildNodes->scalarNode('logger');
if ($this->maxRequestBodySizeIsSupported()) {
$optionsChildNodes->enumNode('max_request_body_size')
->values([
'none',
'small',
'medium',
'always',
]);
}
$optionsChildNodes->integerNode('max_breadcrumbs')
->min(1);
$optionsChildNodes->integerNode('max_value_length')
Expand Down Expand Up @@ -171,12 +180,11 @@ private function isNotAValidCallback(): \Closure

private function classSerializersAreSupported(): bool
{
try {
new Options(['class_serializers' => []]);
return method_exists(Options::class, 'getClassSerializers');
}

return true;
} catch (\Throwable $throwable) {
return false;
}
private function maxRequestBodySizeIsSupported(): bool
{
return method_exists(Options::class, 'getMaxRequestBodySize');
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
'excluded_exceptions',
'http_proxy',
'logger',
'max_request_body_size',
'max_breadcrumbs',
'max_value_length',
'prefixes',
Expand Down
24 changes: 13 additions & 11 deletions test/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@

use PHPUnit\Framework\TestCase;
use Sentry\Options;
use Sentry\SentryBundle\Test\DependencyInjection\ConfigurationTest;

abstract class BaseTestCase extends TestCase
{
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;

protected function classSerializersAreSupported(): bool
{
try {
new Options(['class_serializers' => []]);
return method_exists(Options::class, 'getClassSerializers');
}

return true;
} catch (\Throwable $throwable) {
return false;
}
protected function maxRequestBodySizeIsSupported(): bool
{
return method_exists(Options::class, 'getMaxRequestBodySize');
}

protected function getSupportedOptionsCount(): int
{
$count = 23;

if ($this->classSerializersAreSupported()) {
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
++$count;
}

if ($this->maxRequestBodySizeIsSupported()) {
++$count;
}

return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT;
return $count;
}
}
12 changes: 12 additions & 0 deletions test/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public function optionValuesProvider(): array
}

if ($this->classSerializersAreSupported()) {
$options[] = ['max_request_body_size', 'none'];
$options[] = ['max_request_body_size', 'small'];
$options[] = ['max_request_body_size', 'medium'];
$options[] = ['max_request_body_size', 'always'];
}

if ($this->maxRequestBodySizeIsSupported()) {
$options[] = ['class_serializers', ['count']];
}

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

if ($this->maxRequestBodySizeIsSupported()) {
$values[] = ['max_request_body_size', null];
$values[] = ['max_request_body_size', 'invalid'];
}

return $values;
}

Expand Down
4 changes: 4 additions & 0 deletions test/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public function optionsValueProvider(): array
];
}

if ($this->maxRequestBodySizeIsSupported()) {
$options[] = ['max_request_body_size', 'always'];
}

return $options;
}

Expand Down