Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Add parameters to validate decoded json or not
Browse files Browse the repository at this point in the history
  • Loading branch information
steevanb committed Mar 26, 2019
1 parent d9a3eeb commit bfdcbb8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Decoder/AbstractJsonDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ abstract class AbstractJsonDecoder
/** @var bool */
private $objectAsArray = false;

/** @var bool */
private $validateDecodedData = true;

/** @return mixed */
public function decode(string $json)
public function decode(string $json, bool $validateDecodedData = null)
{
$options = 0;
if ($this->isBigIntAsString()) {
Expand All @@ -53,7 +56,13 @@ public function decode(string $json)
throw new JsonDecodeNullException($json);
}

if (is_array($return)) {
if (
is_array($return)
&& (
(is_bool($validateDecodedData) && $validateDecodedData)
|| (is_bool($validateDecodedData) === false && $this->isValidateDecodedData())
)
) {
$optionResolver = new OptionsResolver();
$this->configureDecodedJson($optionResolver);
$optionResolver->resolve($return);
Expand Down Expand Up @@ -126,4 +135,16 @@ protected function isObjectAsArray(): bool
{
return $this->objectAsArray;
}

protected function setValidateDecodedData(bool $validate): self
{
$this->validateDecodedData = $validate;

return $this;
}

protected function isValidateDecodedData(): bool
{
return $this->validateDecodedData;
}
}

0 comments on commit bfdcbb8

Please sign in to comment.