示例#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());
     }
 }
示例#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);
     }
 }
示例#3
0
 private function arrayToXML($array)
 {
     return \Spatie\ArrayToXml\ArrayToXml::convert($array);
 }
示例#4
0
文件: Result.php 项目: Sohib/Crawler
 public function toXml()
 {
     return ArrayToXml::convert($this->result);
 }
示例#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);
    }
示例#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);
 }
示例#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);
    }