Beispiel #1
0
 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();
 }
Beispiel #2
0
 public function testGetContentType()
 {
     $writer = new Xml();
     $this->assertEquals('application/xml', $writer->getContentType());
 }