src/PHPEncoder.php
private function generate($value, $depth, array $options, array $recursion = [])
    {
        if ($this->detectRecursion($value, $options, $recursion)) {
            $recursion[] = $value;
        }

        if ($options['recursion.max'] !== false && $depth > (int) $options['recursion.max']) {
            throw new \RuntimeException('Maximum encoding depth reached');
        }

        $callback = function ($value, $level = 0, array $overrides = []) use ($depth, $options, $recursion) {
            return $this->generate($value, $depth + (int) $level, $overrides + $options, $recursion);
        };

        return $this->encodeValue($value, $depth, $options, $callback);
    }
private function generate($value, $depth, array $options, array $recursion = [])
    {
        if ($this->detectRecursion($value, $options, $recursion)) {
            $recursion[] = $value;
        }

        if ($options['recursion.max'] !== false && $depth > (int) $options['recursion.max']) {
            throw new \RuntimeException('Maximum encoding depth reached');
        }

        $callback = function ($value, $level = 0, array $overrides = []) use ($depth, $options, $recursion) {
            return $this->generate($value, $depth + (int) $level, $overrides + $options, $recursion);
        };

        return $this->encodeValue($value, $depth, $options, $callback);
    }
private function generate ( $ value , $ depth , array $ options , array $ recursion = [ ] ) { if ( $ this -> detectRecursion ( $ value , $ options , $ recursion ) ) { $ recursion [ ] = $ value ; } if ( $ options [ 'recursion.max' ] !== false && $ depth > ( int ) $ options [ 'recursion.max' ] ) { throw new \ RuntimeException ( 'Maximum encoding depth reached' ) ; } $ callback = function ( $ value , $ level = 0 , array $ overrides = [ ] ) use ( $ depth , $ options , $ recursion ) { return $ this -> generate ( $ value , $ depth + ( int ) $ level , $ overrides + $ options , $ recursion ) ; } ; return $ this -> encodeValue ( $ value , $ depth , $ options , $ callback ) ; }
Generates the code for the given value recursively.
@param mixed $value Value to encode
@param int $depth Current indentation depth of the output
@param array $options List of encoder options
@param array $recursion Previously encoded values for recursion detection
@return string The PHP code that represents the given value
@throws \RuntimeException If max depth is reached or a recursive value is detected
Generates the code for the given value recursively .