Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function dump(array $data) : string
 {
     // @codeCoverageIgnoreStart
     if (!class_exists('Spatie\\ArrayToXml\\ArrayToXml')) {
         throw new RuntimeException('Unable to dump XML, the ArrayToXml dumper is not installed.');
     }
     // @codeCoverageIgnoreEnd
     try {
         return ArrayToXml::convert($data);
     } catch (DOMException $exception) {
         throw new DumpException($exception->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * Translate from json to xml
  *
  * @param  PayloadInterface $payload
  */
 public static function translate(PayloadInterface $payload)
 {
     switch ($payload->getContentType()) {
         case 'text/xml':
         case 'application/xml':
             return clone $payload;
         case 'application/json':
             $obj = new Payload('text/xml');
             $data = json_decode($payload->getContent(), TRUE);
             static::insureValidKeys($data);
             $xml = ArrayToXml::convert($data);
             $obj->setContent($xml);
             return $obj;
         default:
             return static::failedTranslation($payload);
     }
 }
Esempio n. 3
0
 private function arrayToXML($array)
 {
     return \Spatie\ArrayToXml\ArrayToXml::convert($array);
 }
Esempio n. 4
0
 public function toXml()
 {
     return ArrayToXml::convert($this->result);
 }
Esempio n. 5
0
    /**
     * @test
     */
    public function it_can_convert_attributes_to_xml()
    {
        $expectedXml = '<?xml version="1.0"?>
<root><Good_guy nameType="1"><name>Luke Skywalker</name><weapon>Lightsaber</weapon></Good_guy><Bad_guy><name>Sauron</name><weapon>Evil Eye</weapon></Bad_guy></root>' . PHP_EOL;
        $withAttributes = $this->testArray;
        $withAttributes['Good guy']['_attributes'] = ['nameType' => 1];
        $result = ArrayToXml::convert($withAttributes);
        $this->assertEquals($expectedXml, $result);
    }
Esempio n. 6
0
 /**
  * @test
  */
 public function it_will_raise_an_exception_when_spaces_should_not_be_replaced_and_a_key_contains_a_space()
 {
     $this->setExpectedException('DOMException');
     ArrayToXml::convert($this->testArray, '', false);
 }
Esempio n. 7
0
    /**
     * @test
     */
    public function it_can_group_by_values_when_values_are_in_a_numeric_array()
    {
        $array = ['user' => ['foo', 'bar']];
        $expectedXml = '<?xml version="1.0"?>
<root><user>foo</user><user>bar</user></root>' . PHP_EOL;
        $result = ArrayToXml::convert($array);
        $this->assertEquals($expectedXml, $result);
    }