Example #1
0
File: Entry.php Project: 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();
 }
Example #2
0
File: Xml.php Project: seytar/psx
 public function isContentTypeSupported(MediaType $contentType)
 {
     return MediaType\Xml::isMediaType($contentType);
 }