Skip to content

Commit

Permalink
Add overwriteParsedBody
Browse files Browse the repository at this point in the history
  • Loading branch information
Moln committed Sep 5, 2019
1 parent 01e5a95 commit 3297e5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/ContentValidationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class ContentValidationMiddleware implements MiddlewareInterface
const INPUT_FILTER = 'input_filter';

protected $inputFilter;

protected $responseFactory;

protected $overwriteParsedBody = false;

/**
* @return InputFilterInterface
*/
Expand All @@ -48,7 +51,8 @@ public function setInputFilter(InputFilterInterface $inputFilter)
public function __construct(
InputFilterPluginManager $inputFilters = null,
?callable $invalidHandler = null,
?callable $responseFactory = null
?callable $responseFactory = null,
bool $overwriteParsedBody = false
) {
if ($inputFilters) {
$this->setInputFilterManager($inputFilters);
Expand All @@ -61,6 +65,8 @@ public function __construct(
if ($responseFactory) {
$this->setResponseFactory($responseFactory);
}

$this->overwriteParsedBody = $overwriteParsedBody;
}

/**
Expand Down Expand Up @@ -121,6 +127,10 @@ public function process(
);
}

if ($this->overwriteParsedBody) {
$request = $request->withParsedBody($inputFilter->getValues());
}

return $handler->handle($request);
}

Expand Down
6 changes: 5 additions & 1 deletion src/ContentValidationMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public function __invoke(
$requestedName = null,
array $options = null
) {
$config = $container->has('config')
? $container->get('config')['zfegg'][ContentValidationMiddleware::class] ?? []
: [];
$requestedName = $requestedName ?: ContentValidationMiddleware::class;

$response = $container->has(ResponseInterface::class) ?
Expand All @@ -25,7 +28,8 @@ public function __invoke(
return new $requestedName(
$inputFilterManager,
null,
$response
$response,
$config['overwrite_parsed_body'] ?? false
);
}
}

0 comments on commit 3297e5c

Please sign in to comment.