Ejemplo n.º 1
0
Archivo: Entry.php Proyecto: seytar/psx
 public function setContent($content, $type, $src = null)
 {
     $this->writer->startElement('content');
     if (empty($src)) {
         switch ($type) {
             case 'text':
             case 'html':
                 $this->writer->writeAttribute('type', $type);
                 $this->writer->text($content);
                 break;
             case 'xhtml':
                 $this->writer->writeAttribute('type', $type);
                 $this->writer->writeRaw($content);
                 break;
             default:
                 if (!empty($type)) {
                     $this->writer->writeAttribute('type', $type);
                     try {
                         $mediaType = new MediaType($type);
                         if (MediaType\Xml::isMediaType($mediaType)) {
                             if ($content instanceof RecordInterface) {
                                 $writer = new Xml($this->writer);
                                 $writer->write($content);
                             } else {
                                 $this->writer->writeRaw($content);
                             }
                         } else {
                             $this->writer->text($content);
                         }
                     } catch (InvalidArgumentException $e) {
                         // invalid media type
                         $this->writer->text($content);
                     }
                 } else {
                     $this->writer->text($content);
                 }
                 break;
         }
     } else {
         $this->writer->writeAttribute('src', $src);
         if (!empty($type)) {
             $this->writer->writeAttribute('type', $type);
         }
     }
     $this->writer->endElement();
 }
Ejemplo n.º 2
0
    public function testWriteEmpty()
    {
        $writer = new Xml();
        $actual = $writer->write($this->getEmptyRecord());
        $expect = <<<TEXT
<?xml version="1.0" encoding="UTF-8"?>
<record />
TEXT;
        $this->assertXmlStringEqualsXmlString($expect, $actual);
    }