Convert block payloads into json

@param  array $payload
@param  string $module

@return array
976346
public function parseBlocks($payload, $module)
    {
        $blockCollection = [];

        foreach ($payload as $key => $value) {
            if (stristr($key, 'block_')) {
                $blockName = str_replace('block_', '', $key);
                $blockCollection[$blockName] = $value;
                unset($payload[$key]);
            }
        }

        $blockCollection = $this->parseTemplate($payload, $blockCollection, $module);

        if (empty($blockCollection)) {
            $payload['blocks'] = "{}";
        } else {
            $payload['blocks'] = json_encode($blockCollection);
        }

        return $payload;
    }
1007477
public function encode(Payload $payload)
    {
        $token = $this->jwt->encode($payload->get());

        return new Token($token);
    }
609468
public function callBlock(string $block = '', ...$params): ?string
    {
        /** @var ModuleBlockInterface|null $module */
        $module = $this->module_service
            ->findByComponent(ModuleBlockInterface::class, $this->tree, Auth::user())
            ->first(static function (ModuleInterface $module) use ($block): bool {
                return $module->name() === $block && $module->name() !== 'html';
            });

        if ($module === null) {
            return '';
        }

        // Build the config array
        $cfg = [];
        foreach ($params as $config) {
            $bits = explode('=', $config);

            if (count($bits) < 2) {
                continue;
            }

            $v       = array_shift($bits);
            $cfg[$v] = implode('=', $bits);
        }

        return $module->getBlock($this->tree, 0, '', $cfg);
    }
133117
public function getPayload($module, $methodName)
    {
        $payloads = array();

        $config = $this->getServiceLocator()->get('MelisCoreConfig');
        $payloads = $config->getItem('diagnostic/'.$module.'/methods/'. $this->getMethodName($methodName) .'/payloads');

        return $payloads;

    }
1222623
protected function decodePayload(& $packet_data, & $payload_pos)
    {
        $return_code = array();

        while (isset($packet_data[$payload_pos])) {
            $return_code[] = ord($packet_data[$payload_pos]);

            ++ $payload_pos;
        }

        $this->return_codes = $return_code;
    }
516846
public function format($payload)
    {
        $payload = $this->fill($payload);
        return "[".$payload['responsecode']."] ".$payload['message']."<br />".$payload['verbosemessage']."<br/>".$payload['url'];

    }
785510
public static function generateToken($payload = null)
    {
        if (empty($payload)) {
            return false;
        }

        $token = JWT::encode($payload, Configure::read('ApiRequest.jwtAuth.cypherKey'), Configure::read('ApiRequest.jwtAuth.tokenAlgorithm'));

        return $token;
    }
214335
function payload()
    {
        if ( $this->IsFault )
        {
            return json_encode( array(
                'content' => null,
                'error_text' => $this->FaultString() ) );
        }
        else
        {
            return json_encode( array(
                'content' => $this->Value,
                'error_text' => null ) );
        }
    }
355804
public function parse($payload)
    {
        if ($payload) {
            try {
                $xml = simplexml_load_string($payload, 'SimpleXMLElement', (LIBXML_VERSION >= 20700) ? (LIBXML_PARSEHUGE | LIBXML_NOCDATA) : LIBXML_NOCDATA);
                $ns = ['' => null] + $xml->getDocNamespaces(true);
                return $this->recursive_parse($xml, $ns);
            } catch (\Exception $ex) {
                throw new ParserException('Failed To Parse XML');
            }
        }

        return [];
    }
1065565
final public function process($payload)
    {
        $payload = $this->processor->processStack($payload, $this->stack);

        if ( $this->next instanceof PipeChainInterface ) {
            $payload = $this->next->process($payload);
        }

        return $payload;
    }
124754
public function process($payload)
    {
        foreach ($this->stages as $stage) {
            $payload = call_user_func($stage, $payload);
        }
        return $payload;
    }
1296930
function buildPayload(&$payload)
    {
        if (is_array($payload)) {
            $payload = $this->array_map_deep($payload, array($this, 'buildPayloadItemInfo'));
        } else {
            $payload = $this->makePayloadBuilder($payload);
            $this->buildPayload($payload);
        }

        return $payload;
    }
897585
protected function serialize($payload)
    {
        // convert identifier to Doctrine object
        if (is_array($payload) || is_scalar($payload)) {
            // just use the id when no keys are given (Doctrine expects an array like [id: 1234]
            if (is_array($payload) && is_numeric(key($payload))) {
                $payload = current($payload);
            }

            $payload = $this->doctrine->getRepository($this->className)->find($payload);
        }

        // anything else is just wrong at this point
        if (!is_object($payload) || !($payload instanceof $this->className)) {
            throw new \RuntimeException(
                sprintf('Expecting object of type %s, but got %s', $this->className, var_export($payload, true))
            );
        }

        return parent::serialize($payload);
    }
820529
public function serialize($payload)
    {
        $serialized = '';
        foreach ($payload as $line) {
            $serialized .= '"' . implode('","', $line) . '"' . "\n";
        }
        return $serialized;
    }
935306
protected function getJsonPayload($payload)
    {
        $payload = json_decode(base64_decode($payload), true);

        // If the payload is not valid JSON or does not have the proper keys set we will
        // assume it is invalid and bail out of the routine since we will not be able
        // to decrypt the given value. We'll also check the MAC for this encryption.
        if (! $payload || $this->invalidPayload($payload)) {
            throw new DecryptException('The payload is invalid.');
        }

        if (! $this->validMac($payload)) {
            throw new DecryptException('The MAC is invalid.');
        }

        return $payload;
    }
1262829
public function setPayload($payload)
    {
        $this->payload = $payload;

        $this->setPayloadType(gettype($payload));

        if ($payload instanceof EntityDataModel) {
            $this->setPayloadType("EntityDataModel");
        }

        if ($payload instanceof EntityCollection) {
            $this->setPayloadType("EntityCollection");
            if ($payload->isPaginated()) {
                $this->setPayloadMeta([
                    'total' => $payload->getOriginalCount(),
                    'returned' => $payload->getCount(),
                    'page' => $payload->getPage(),
                    'perPage' => $payload->getPerPage()
                ]);
            }
        }

        return $this;
    }
1093595
private static function preprocessJsonPayload($payload) {

        $requests = [];

        $is_batch = false;

        if ( is_array($payload) ) {

            $is_batch = true;

            foreach ( $payload as $request ) $requests[] = self::preprocessJsonRequest($request);

        } else {

            $requests[] = self::preprocessJsonRequest($payload);

        }

        return array($is_batch, $requests);

    }