@param JsonRpcCall $jsonRpcCall
@param array       $decodedContent

@return void

@throws \Exception
550885
private function populateItem(JsonRpcCall $jsonRpcCall, array $decodedContent) : void
    {
        // convert to array in any cases for simpler use
        $itemList = $jsonRpcCall->isBatch() ? $decodedContent : [$decodedContent];
        foreach ($itemList as $itemPosition => $item) {
            // Safely denormalize items
            try {
                $item = $this->requestDenormalizer->denormalize($item);

                $jsonRpcCall->addRequestItem($item);
            } catch (\Exception $exception) {
                if (false === $jsonRpcCall->isBatch()) {
                    // If it's not a batch call, throw the exception
                    throw $exception;
                }
                // Else populate the item (exception will be managed later
                $jsonRpcCall->addExceptionItem($exception);
            }
        }
    }
164715
public static function log($type, $source): void
    {
        if (
            (!($source instanceof \stdClass) && $type === self::TYPE_EXCEPTION) ||
            (!($source instanceof JsonRpcRequest) && \in_array($type, [self::TYPE_REQUEST, self::TYPE_RESPONSE], true))
        ) {
            return;
        }

        /** @var JsonRpcRequest $jsonRpcRequest */
        $jsonRpcRequest = app('JsonRpcRequest');
        $hideIndices = !empty($jsonRpcRequest->controller->hideDataLog) ? $jsonRpcRequest->controller->hideDataLog : false;
        $method = !empty($jsonRpcRequest->method) ? $jsonRpcRequest->method : 'Unknown';

        switch ($type) {
            case self::TYPE_REQUEST:
                $logLevel = 'info';
                $message = 'Request';
                $context = !empty($source->call) ? (array)$source->call : [];
                break;

            case self::TYPE_RESPONSE:
                $logLevel = 'info';
                $message = sprintf('Successful request to method "%s" (id-%s) with params: ', $source->method, $source->id);
                $context = !empty($source->call) ? (array)$source->call : [];
                break;

            case self::TYPE_EXCEPTION:
                $logLevel = 'error';
                $message = sprintf('JsonRpcException %d: %s',
                    isset($source->code) ? $source->code : 0,
                    !empty($source->message) ? $source->message : '');
                $context = !empty($jsonRpcRequest->call) ? (array)$jsonRpcRequest->call : [];
                break;

            default:
                $logLevel = 'info';
                $message = 'No log type specified';
                $context['params'] = [];
                break;
        }

        $hideDataRules = !empty($hideIndices[$type][$method])
            ? $hideIndices[$type][$method]
            : false;

        $hideData = function (&$item, $key, $rules) {
            if (\in_array($key, $rules, true)) {
                $item = '****';
            }
        };

        if ($hideDataRules && !empty($context['params'])) {
            array_walk($context['params'], $hideData, $hideDataRules);
        }

        Log::channel(config('jsonrpc.log_channel'))
            ->$logLevel($message, $context);

    }
502442
public function setDataContent($content)
    {
        if (is_array($content)) {
            $this->headers->set('Content-Type', 'application/json');
            $content = json_encode($content);
        }

        $this->setContent($content);
    }
130097
public function decode($jsonString)
    {
        $jsonString = $this->normalize($jsonString);
        $this->parser->parse($jsonString);

        return json_decode($jsonString, true);
    }
439419
protected function executeGetContentQueries($decoded)
    {
        // Perform actual queries and hydrate
        $totalResults = false;
        $results = false;
        foreach ($decoded['queries'] as $query) {
            $statement = sprintf(
                'SELECT %s.* %s %s %s',
                $query['tablename'],
                $query['from'],
                $query['where'],
                $query['order']
            );

            if ($decoded['self_paginated'] === true) {
                // self pagination requires an extra query to return the actual number of results
                if ($decoded['return_single'] === false) {
                    $countStatement = sprintf(
                        'SELECT COUNT(*) as count %s %s',
                        $query['from'],
                        $query['where']
                    );
                    $countRow = $this->app['db']->executeQuery($countStatement)->fetch();
                    $totalResults = $countRow['count'];
                }

                if (isset($decoded['parameters']['paging']) && $decoded['parameters']['paging'] === true) {
                    $offset = ($decoded['parameters']['page'] - 1) * $decoded['parameters']['limit'];
                } else {
                    $offset = null;
                }
                $limit = $decoded['parameters']['limit'];

                // @todo this will fail when actually using params on certain databases
                $statement = $this->app['db']->getDatabasePlatform()->modifyLimitQuery($statement, $limit, $offset);
            } elseif (!empty($decoded['parameters']['limit'])) {
                // If we're not paging, but we _did_ provide a limit.
                $limit = $decoded['parameters']['limit'];
                $statement = $this->app['db']->getDatabasePlatform()->modifyLimitQuery($statement, $limit);
            }

            if (!empty($decoded['parameters']['printquery'])) {
                // @todo formalize this
                echo nl2br(htmlentities($statement));
            }

            $rows = $this->app['db']->fetchAll($statement, $query['params']);

            // Convert the row 'arrays' into \Bolt\Legacy\Content objects.
            // Only get the Taxonomies and Relations if we have to.
            $rows = $this->hydrateRows($query['contenttype'], $rows, $decoded['hydrate']);

            if ($results === false) {
                $results = $rows;
            } else {
                // We can no longer maintain keys when merging subresults
                $results = array_merge($results, array_values($rows));
            }
        }

        if ($totalResults === false) {
            $totalResults = count($results);
        }

        return [$results, $totalResults];
    }
166242
protected function getResponseString(
        JsonRpcCallResponse $jsonRpcCallResponse,
        JsonRpcCall $jsonRpcCall = null
    ) : string {
        $response = $this->jsonRpcCallSerializer->serialize($jsonRpcCallResponse);

        $event = new AcknowledgeEvent\OnResponseSendingEvent($response, $jsonRpcCallResponse, $jsonRpcCall);
        $this->dispatchJsonRpcEvent($event::EVENT_NAME, $event);

        return $response;
    }
375594
public function theJsonNodeShouldNotExist($jsonNode)
    {
        $e = null;

        try {
            $realValue = $this->evaluateJsonNodeValue($jsonNode);
        } catch (\Exception $e) {
            // If the node does not exist an exception should be throwed
        }

        if ($e === null) {
            throw new WrongJsonExpectation(
                sprintf("The node '%s' exists and contains '%s'.", $jsonNode, json_encode($realValue)),
                $this->readJson(),
                $e
            );
        }
    }
18987
public function onSinglePageLoaded(array &$pageData)
    {
        if (!isset($pageData['content'])) {
            $pageData['content'] = $this->prepareFileContent($pageData['raw_content'], $pageData['meta']);
            $pageData['content'] = $this->parseFileContent($pageData['content']);
        }
    }
767532
protected static function throwDecodingExceptionIfOccurred($json)
    {
        if (JSON_ERROR_NONE === json_last_error()) {
            return;
        }

        $decodingException = new DecodingException(
            sprintf('JSON decoding failed: %s', json_last_error_msg()),
            json_last_error()
        );

        $decodingException->setDecodingData($json);

        throw $decodingException;
    }
812143
public function theResponseShouldContainJson(PyStringNode $jsonString)
    {
        $etalon = json_decode($this->replacePlaceHolder($jsonString->getRaw()), true);
        $actual = json_decode($this->response->getBody(), true);

        if (null === $etalon) {
            throw new \RuntimeException(
              "Can not convert etalon to json:\n" . $this->replacePlaceHolder($jsonString->getRaw())
            );
        }

        if (null === $actual) {
            throw new \RuntimeException(
              "Can not convert actual to json:\n" . $this->replacePlaceHolder((string) $this->response->getBody())
            );
        }

        Assertions::assertGreaterThanOrEqual(count($etalon), count($actual));
        foreach ($etalon as $key => $needle) {
            Assertions::assertArrayHasKey($key, $actual);
            Assertions::assertEquals($etalon[$key], $actual[$key]);
        }
    }
719331
public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT, bool $types = null)
    {
        if (!$this->memberSet && !$this->memberList && !$this->memberChoice) {
            $this->memberSet = new Set();
        }

        return parent::jsonLDSerialize($context, $types);
    }
314793
public function onKernelException(GetResponseForExceptionEvent $event): void
    {
        $exception = $event->getException();

        if (!$exception instanceof AccessDeniedException) {
            return;
        }

        $event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
    }
751788
public function getJsonAsArray($url, $useragent = 'PHP/cURL', $timeout = 5, $customHeaders = false, $postArray = array())
    {
        $result = $this->BackyardHttp->getData($url, $useragent, $timeout, $customHeaders, $postArray);
        $json = $result['message_body'];
        if (!$json) {
            $this->BackyardError->log(2, "No content on {$url}");
            return false;
        }
        $jsonArray = $this->jsonCleanDecode($json, true);
        if (!$jsonArray) {
            $this->BackyardError->log(2, "Trouble with decoding JSON from {$url}");
            return false;
        }
        return $jsonArray;
    }
785631
private function parseJson($jsonString)
    {
        $jsonData = json_decode($jsonString, true);

        if ($jsonData === null) {
            $this->emit('error', [json_last_error_msg()]);
            return;
        }

        $this->setContent($jsonString);
        $this->setData($jsonData);
        $this->emit('end');
    }
716498
public static function allowOnlyJsonRequest($jsonpAttribute = 'callback')
    {
        if (static::isJsonRequested() === false) {
            throw new BadRequestHttpException();
        }
        Yii::$app->response->format =
            Yii::$app->request->get($jsonpAttribute)
                ? Response::FORMAT_JSONP
                : Response::FORMAT_JSON;
    }
1040115
private function createCache($renderedContent)
    {
        if (!CmsComponent::isCmsLoggedIn()) {
            Cache::getInstance()->setCacheForPath(Request::$requestUri, $renderedContent, json_encode(ResponseHeaders::getHeaders()));
        }
    }
1260877
public function tryDecodeData(&$decodedData)
    {
        $hasOutput = false;

        switch ($this->getEncoding()) {
            case self::ENCODING_URL_ENCODED_OCTETS:
                $decodedData = rawurldecode($this->getEncodedData());
                $hasOutput = true;
                break;
            case self::ENCODING_BASE64:
                $b64Decoded = base64_decode($this->getEncodedData(), true);

                if ($b64Decoded !== false) {
                    $decodedData = $b64Decoded;
                    $hasOutput = true;
                }
                break;
            default:
                // NOP
                break;
        }

        return $hasOutput;
    }