/** * @param $format * * @return array|mixed */ private function decode($format) { $data = $this->decoder->decode((string) $this->apiContext->getResponse()->getBody(), $format); if ($format === 'xml') { $data = !empty($data) ? is_int(key($data['entry'])) ? $data['entry'] : [$data['entry']] : []; } return $data; }
public function decode($data, $format) { $context = []; if ($format === 'json') { // the JSON schema validator need an object hierarchy $context['json_decode_associative'] = false; } $decoded = $this->decoder->decode($data, $format, $context); if ($format === 'xml') { // the JSON schema validator need an object hierarchy $decoded = json_decode(json_encode($decoded)); } return $decoded; }
/** * @param $format * * @return array|mixed */ private function decode($format) { $data = $this->decoder->decode((string) $this->apiContext->getResponse()->getBody(), $format); if ($format === 'json' && isset($data['_embedded']['items'])) { $data = $data['_embedded']['items']; } if ($format === 'xml') { if (!empty($data) && isset($data['entry'])) { if (is_int(key($data['entry']))) { $data = $data['entry']; } elseif (isset($data['entry']['@rel'])) { $data = array_pop($data['entry']); } else { $data = [$data['entry']]; } } else { $data = []; } } return $data; }
/** * Decodes the request body * * @param Request $request The request * * @return void */ protected function decodeBody(Request $request) { if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH', 'DELETE'])) { $contentType = $request->headers->get('Content-Type', ''); $format = $this->formatNegotiator->getFormat($contentType); if (!$this->contentDecoder->supportsDecoding($format)) { return; } $content = $request->getContent(); if (!empty($content)) { try { $data = $this->contentDecoder->decode($content, $format); } catch (Exception $exception) { $data = null; } if (is_array($data)) { $request->request->replace($data); } else { $message = sprintf('Invalid %s message received', $format); throw new BadRequestHttpException($message); } } } }
/** * {@inheritdoc} */ public function decode($data, array $context = []) { return $this->serializer->decode($data, JsonEncoder::FORMAT, $context); }