protected function _addDebugNode($json)
    {
        $viewVars = $this->controller->viewVars;

        if (empty($viewVars['error'])) {
            return $json;
        }

        $debug = [];
        $debug['class'] = get_class($viewVars['error']);

        if (!isset($debug['trace'])) {
            $debug['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), [
                'format' => 'array',
                'args' => false
            ]);
        }

        $result = json_decode($json, true);
        $result['debug'] = $debug;

        try {
            return json_encode($result, JSON_PRETTY_PRINT);
        } catch (\Exception $e) {
            $result['debug']['message'] = $e->getMessage();
            $result['debug']['trace'] = [
                'error' => 'Unable to encode stack trace',
            ];

            return json_encode($result, JSON_PRETTY_PRINT);
        }
    }
protected function _addDebugNode($json)
    {
        $viewVars = $this->controller->viewVars;

        if (empty($viewVars['error'])) {
            return $json;
        }

        $debug = [];
        $debug['class'] = get_class($viewVars['error']);

        if (!isset($debug['trace'])) {
            $debug['trace'] = Debugger::formatTrace($viewVars['error']->getTrace(), [
                'format' => 'array',
                'args' => false
            ]);
        }

        $result = json_decode($json, true);
        $result['debug'] = $debug;

        try {
            return json_encode($result, JSON_PRETTY_PRINT);
        } catch (\Exception $e) {
            $result['debug']['message'] = $e->getMessage();
            $result['debug']['trace'] = [
                'error' => 'Unable to encode stack trace',
            ];

            return json_encode($result, JSON_PRETTY_PRINT);
        }
    }
protected function _addDebugNode ( $ json ) { $ viewVars = $ this -> controller -> viewVars ; if ( empty ( $ viewVars [ 'error' ] ) ) { return $ json ; } $ debug = [ ] ; $ debug [ 'class' ] = get_class ( $ viewVars [ 'error' ] ) ; if ( ! isset ( $ debug [ 'trace' ] ) ) { $ debug [ 'trace' ] = Debugger :: formatTrace ( $ viewVars [ 'error' ] -> getTrace ( ) , [ 'format' => 'array' , 'args' => false ] ) ; } $ result = json_decode ( $ json , true ) ; $ result [ 'debug' ] = $ debug ; try { return json_encode ( $ result , JSON_PRETTY_PRINT ) ; } catch ( \ Exception $ e ) { $ result [ 'debug' ] [ 'message' ] = $ e -> getMessage ( ) ; $ result [ 'debug' ] [ 'trace' ] = [ 'error' => 'Unable to encode stack trace' , ] ; return json_encode ( $ result , JSON_PRETTY_PRINT ) ; } }
Adds top-level `debug` node to a json encoded string

@param string $json Json encoded string
@return string Json encoded string with added debug node
Adds top - level debug node to a json encoded string