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
 public function accept(MediaType $contentType)
 {
     return in_array($contentType->getName(), MediaType\Xml::getMediaTypes()) || substr($contentType->getSubType(), -4) == '+xml' || substr($contentType->getSubType(), -4) == '/xml';
 }
Example #3
0
File: Xml.php Project: seytar/psx
 public function isContentTypeSupported(MediaType $contentType)
 {
     return MediaType\Xml::isMediaType($contentType);
 }
Example #4
0
File: Atom.php Project: seytar/psx
 public static function textConstruct(DOMElement $el)
 {
     $text = new \stdClass();
     $type = strtolower($el->getAttribute('type'));
     if (empty($type) || $type == 'text' || $type == 'html' || substr($type, 0, 5) == 'text/') {
         $content = $el->nodeValue;
     } elseif ($type == 'xhtml' || in_array($type, MediaType\Xml::getMediaTypes()) || substr($type, -4) == '+xml' || substr($type, -4) == '/xml') {
         // get first child element
         $child = null;
         foreach ($el->childNodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE) {
                 $child = $node;
                 break;
             }
         }
         if ($child !== null) {
             $content = $el->ownerDocument->saveXML($child);
         } else {
             $content = null;
         }
     } else {
         $content = base64_decode($el->nodeValue);
     }
     if (!empty($type)) {
         $text->type = $type;
     }
     $text->content = $content;
     return $text;
 }