Author: Jordi Boggiano (j.boggiano@seld.be)
Author: John Wards (jwards@whiteoctober.co.uk)
Author: Fabian Vogler (fabian@equivalence.ch)
Inheritance: extends Symfony\Component\Serializer\Encoder\SerializerAwareEncoder, implements Symfony\Component\Serializer\Encoder\EncoderInterface, implements Symfony\Component\Serializer\Encoder\DecoderInterface, implements NormalizationAwareInterface
コード例 #1
1
ファイル: XmlResponseHandler.php プロジェクト: Erliz/thetvdb
 /**
  * @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;
 }
コード例 #2
0
 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');
 }
コード例 #3
0
 /**
  * @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();
 }
コード例 #4
0
 /**
  * @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());
 }
コード例 #5
0
 /**
  * @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);
 }
コード例 #6
0
 /**
  * @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);
 }
コード例 #7
0
ファイル: RequestBodyDecoder.php プロジェクト: jsor/stack-hal
 /**
  * @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);
 }
コード例 #8
0
ファイル: XmlEncoderTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * 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'));
 }
コード例 #9
0
ファイル: PhpmdGadget.php プロジェクト: simpspector/analyser
 /**
  * @param string $xml
  * @return array
  */
 private function convertFromXmlToArray($xml)
 {
     $encoder = new XmlEncoder('pmd');
     return $encoder->decode($xml, 'xml');
 }