/** * @param $rootNodeName * @return array|mixed|string * @throws InvalidXmlInResponseException */ protected function getData($rootNodeName) { $encoder = new XmlEncoder($rootNodeName); try { $data = $encoder->decode($this->xml, 'xml'); } catch (UnexpectedValueException $e) { throw new InvalidXmlInResponseException($e->getMessage()); } return $data; }
public function computeData($grid) { $xmlEncoder = new XmlEncoder(); $xmlEncoder->setRootNodeName('grid'); $serializer = new Serializer(array(new GetSetMethodNormalizer()), array('xml' => $xmlEncoder)); $data = $this->getGridData($grid); $convertData['titles'] = $data['titles']; $convertData['rows']['row'] = $data['rows']; $this->content = $serializer->serialize($convertData, 'xml'); }
/** * @inheritdoc * @throws UnimplementedAttributeException */ public function handle() { $encoder = new XmlEncoder('Showinfo'); try { $data = $encoder->decode($this->xml, 'xml'); } catch (UnexpectedValueException $e) { throw new InvalidXmlInResponseException($e->getMessage()); } if (is_array($data) && count($data) !== 0) { $data = $this->trimArray($data); $show = $this->denormalizeDetailedShow($data); return new ShowResponse($show); } return new ShowResponse(); }
/** * @inheritdoc * @throws UnimplementedAttributeException */ public function handle() { $encoder = new XmlEncoder('Show'); try { $data = $encoder->decode($this->xml, 'xml'); } catch (UnexpectedValueException $e) { throw new InvalidXmlInResponseException($e->getMessage()); } if (!is_array($data) || !array_key_exists('Episodelist', $data)) { return new SeasonsResponse(); } $data = $this->trimArray($data); $show = $this->denormalizeDetailedShow($data); return new SeasonsResponse($show->getSeasons()); }
/** * @inheritdoc * @throws UnimplementedAttributeException */ public function handle() { $encoder = new XmlEncoder('Results'); try { $data = $encoder->decode($this->xml, 'xml'); } catch (UnexpectedValueException $e) { throw new InvalidXmlInResponseException($e->getMessage()); } // Search has no results if (is_string($data) && $data === '0') { return new ShowsResponse(); } if (!is_array($data) || !array_key_exists('show', $data)) { throw new InvalidXmlInResponseException('No `show` element found in XML data.'); } $data = $this->trimArray($data); $shows = $this->denormalize($data['show']); return new ShowsResponse($shows); }
/** * @inheritdoc */ public function handle() { $encoder = new XmlEncoder('show'); try { $data = $encoder->decode($this->xml, 'xml'); } catch (UnexpectedValueException $e) { throw new InvalidXmlInResponseException($e->getMessage()); } if (!is_array($data) || !array_key_exists('episode', $data) && !array_key_exists('latestepisode', $data)) { return new EpisodeResponse(null, null); } $data = $this->trimArray($data); $episode = $latestEpisode = null; if (array_key_exists('episode', $data)) { $episode = $this->handleEpisode($data['episode']); } if (array_key_exists('latestepisode', $data)) { $latestEpisode = $this->handleEpisode($data['latestepisode']); } return new EpisodeResponse($latestEpisode, $episode); }
/** * @param callable[] $decoders */ public static function decode(Request $request, array $decoders = null) { if (null === $decoders) { $decoders = ['json' => function ($content) { $encoder = new JsonEncoder(); return $encoder->decode($content, 'json'); }, 'xml' => function ($content) { $encoder = new XmlEncoder(); return $encoder->decode($content, 'xml'); }]; } if (!self::isDecodeable($request)) { return; } $contentType = $request->headers->get('Content-Type'); $format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType); if (!$format || !isset($decoders[$format])) { return; } if (!is_callable($decoders[$format])) { return; } $content = $request->getContent(); if (!$content) { return; } try { $data = call_user_func($decoders[$format], $content); } catch (\Exception $e) { throw new BadRequestHttpException('Invalid ' . $format . ' message received', $e); } if (!is_array($data)) { throw new BadRequestHttpException('Invalid ' . $format . ' message received'); } $request->request->replace($data); }
/** * Tests the decode() method. */ public function testDecode() { $this->baseEncoder->expects($this->once())->method('decode')->with('test', 'test', array())->will($this->returnValue($this->testArray)); $this->assertEquals($this->testArray, $this->encoder->decode('test', 'test')); }
/** * @param string $xml * @return array */ private function convertFromXmlToArray($xml) { $encoder = new XmlEncoder('pmd'); return $encoder->decode($xml, 'xml'); }