Webmozart\Json\JsonDecoder::setMaxDepth PHP Method

setMaxDepth() public method

If the depth is exceeded during decoding, an {@link DecodingnFailedException} will be thrown. A depth of zero means that objects are not allowed. A depth of one means only one level of objects or arrays is allowed.
public setMaxDepth ( integer $maxDepth )
$maxDepth integer The maximum recursion depth
    public function setMaxDepth($maxDepth)
    {
        if (!is_int($maxDepth)) {
            throw new \InvalidArgumentException(sprintf('The maximum depth should be an integer. Got: %s', is_object($maxDepth) ? get_class($maxDepth) : gettype($maxDepth)));
        }
        if ($maxDepth < 1) {
            throw new \InvalidArgumentException(sprintf('The maximum depth should 1 or greater. Got: %s', $maxDepth));
        }
        $this->maxDepth = $maxDepth;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testMaxDepthMustBeOneOrGreater()
 {
     $this->decoder->setMaxDepth(0);
 }