Parse Payload Data

@param string $payload

@throws ParserException
@return array
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 [];
    }
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);
    }
845635
public function process(Payload $payload) {
		$output = array();
		$command = $this->getCommand();
		// run composer update
		$this->invokeShellCommand($command, $output);
		$payload->getResponse()->addOutputFromPlugin($this, $output);
	}
1048987
public function encode(Payload $payload)
    {
        $token = $this->provider->encode($payload->get());

        return new Token($token);
    }
1037230
private function uncan($payload) {

        $decoded = null;

        if ( empty($payload) || !is_string($payload) ) throw new RpcException("Invalid Request", -32600);

        if ( substr($payload, 0, 27) == 'comodojo_encrypted_request-' ) {

            if ( empty($this->encrypt) ) throw new RpcException("Transport error", -32300);

            $this->request_is_encrypted = true;

            $aes = new AES();

            $aes->setKey($this->encrypt);

            $payload = $aes->decrypt(base64_decode(substr($payload, 27)));

            if ( $payload == false ) throw new RpcException("Transport error", -32300);

        }

        if ( $this->protocol == 'xml' ) {

            $decoder = new XmlrpcDecoder();

            try {

                $decoded = $decoder->decodeCall($payload);

            } catch (XmlrpcException $xe) {

                throw new RpcException("Parse error", -32700);

            }

        } else if ( $this->protocol == 'json' ) {

            if ( strtolower($this->encoding) != 'utf-8' ) {

                $payload = mb_convert_encoding($payload, "UTF-8", strtoupper($this->encoding));

            }

            $decoded = json_decode($payload, false /*DO RAW conversion*/);

            if ( is_null($decoded) ) throw new RpcException("Parse error", -32700);

        } else {

            throw new RpcException("Transport error", -32300);

        }

        return $decoded;

    }
27296
protected function consumeQueue($payload)
  {

    $message = $payload->body;
    try {
      if ($this->isSerialized($message)) {
        $this->message = unserialize($message);
      } else {
        $this->message = json_decode($message, true);
      }
      $this->message['original'] = $this->message;
      $this->message['payload'] = $payload;
      $this->statHat->ezCount('MB_Toolbox: MB_Toolbox_BaseConsumer: consumeQueue', 1);
    } catch (Exception $e) {
      echo 'MB_Toolbox_BaseConsumer: Error processing payload->body: consumeQueue(): ' . $e->getMessage();
      $this->statHat->ezCount('MB_Toolbox: MB_Toolbox_BaseConsumer: consumeQueue Exception', 1);
    }
  }
1171980
public static function unserializeMessagePayload($payload)
    {
        $message = json_decode($payload, true);
        if (json_last_error() === JSON_ERROR_NONE) {
            return $message;
        }

        return $payload;
    }
1109052
public function sendSoap($payload)
    {
        $options = [
            CURLOPT_URL            => $this->getUrl(),
            CURLOPT_CONNECTTIMEOUT => 5,
            CURLOPT_TIMEOUT        => 5,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => $payload,
            CURLOPT_SSLVERSION     => CURL_SSLVERSION_TLSv1_2,
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_CAINFO         => $this->getRootCertificatePath(),
        ];

        $curlHandle = curl_init();
        curl_setopt_array($curlHandle, $options);

        $this->setLastRequest($payload);

        $response = curl_exec($curlHandle);
        $code = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
        $error = curl_error($curlHandle);

        $this->setErrorCode($code);
        $this->setLastResponse($response);

        curl_close($curlHandle);

        if ($response) {
            return $this->parseResponse($response, $code);
        } else {
            throw new Exception($error);
        }
    }
713224
public static function manipulate(Payload $payload, $callback)
    {
        self::assert_callable($callback);

        $payload->replaceData($callback($payload->extractTypeData()));

        return $payload;
    }
394839
public function canHandle($payload)
    {
        if (is_object($payload) && is_a($payload, $this->payloadClassName)) {
            return true;
        } elseif (is_string($payload) && is_subclass_of($payload, $this->payloadClassName)) {
            return true;
        } else {
            return false;
        }
    }
1152870
function parseRequest( $payload )
    {
        $request = new ggJSONRPCRequest();
        if ( $request->decodeStream( $payload ) )
        {
            $this->Id = $request->id();
            return $request;
        }
        else
        {
            return false;
        }
    }
799366
public function parse(string $payload): ResultSpec
    {
        $data = @json_decode($payload, true);

        if (!is_array($data)) {
            throw new BaseClientException('Parse error', JsonRpcException::PARSE_ERROR);
        }

        $units = [];

        if ($this->isSingleResponse($data)) {
            $units[] = $this->decodeResult($data);
            return new ResultSpec($units, true);
        }

        /** @var array $data */
        foreach ($data as $response) {
            $units[] = $this->decodeResult($response);
        }

        return new ResultSpec($units, false);
    }
1136393
protected function normalize($payload)
    {
        $data = get_object_vars($payload);
        foreach ($data as $k => $v) {
            if ($v instanceof \DateTime) {
                $payload->$k = $v->format('c');
                continue;
            }
            if (is_object($v)) {
                $payload->$k = $this->normalize($v);
                continue;
            }
        }
        return $payload;
    }
35570
public function setPayload($payload)
    {
        $this->payload = (string)$payload;
        $this->payloadLength = strlen($payload);
        if ($this->payloadLength > static::MAXIMUM_FRAME_PAYLOAD) {
            throw new OverflowException('Payload too long - it must be smaller or equal ' . static::MAXIMUM_FRAME_PAYLOAD . ' bytes');
        }

        if ($this->payloadLength < 126) {
            $this->logger->debug("setPayload encode as 7bit [l=" . $this->payloadLength . "]");
            $this->payloadLengthDiscriminator = $this->payloadLength;

        } elseif ($this->payloadLength <= 65535) {
            $this->logger->debug("setPayload encode as 16bit [l=" . $this->payloadLength . "]");
            $this->payloadLengthDiscriminator = 126;

        } else {
            $this->logger->debug("setPayload encode as 63bit [l=" . $this->payloadLength . "]");
            $this->payloadLengthDiscriminator = 127;
        }

        $this->secondFrameByte = $this->payloadLengthDiscriminator | $this->secondFrameByte & ~127; //Is there a easier way?
    }
1283516
protected function resolveAndHandle(array $payload)
    {
        list($class, $method) = Str::parseCallback($payload['job'], 'handle');

        $this->instance = $this->resolve($class);

        call_user_func(array($this->instance, $method), $this, $payload['data']);
    }
814371
public function withPayload($payload): self
    {
        $payload = \is_string($payload) ? $payload : $this->jsonConverter->encode($payload);
        if (false === \mb_detect_encoding($payload, 'UTF-8', true)) {
            throw new \InvalidArgumentException('The payload must be encoded in UTF-8');
        }
        $clone = clone $this;
        $clone->payload = $payload;

        return $clone;
    }
1286990
protected function fetchPropertyValues($payload)
    {
        $propertyMap = $this->getPropertiesMap();
        $data = [];
        foreach ($payload['data'] as $resource) {
            $resource = (object)$resource;
            $resource = new \core_kernel_classes_Resource($resource->subject);
            $resourceData = $resource->getPropertiesValues($propertyMap);
            $entityInfo = array_map(function($row) use($resourceData) {
                $stringData = array_map(function($value){
                    return ($value instanceof \core_kernel_classes_Resource) ? $value->getUri() : (string) $value;
                }, $resourceData[$row]);
                return join(',', $stringData);
            }, $propertyMap);

            $entityInfo['uri'] = $resource->getUri();
            $entityInfo['id'] = \tao_helpers_Uri::encode($resource->getUri());
            $data[] = $entityInfo;
        }
        $payload['data'] = $data;

        return $payload;
    }