예제 #1
0
파일: Entry.php 프로젝트: 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();
 }
예제 #2
0
파일: XmlArray.php 프로젝트: seytar/psx
 public function accept(MediaType $contentType)
 {
     return in_array($contentType->getName(), MediaType\Xml::getMediaTypes()) || substr($contentType->getSubType(), -4) == '+xml' || substr($contentType->getSubType(), -4) == '/xml';
 }
예제 #3
0
파일: Xml.php 프로젝트: seytar/psx
 public function isContentTypeSupported(MediaType $contentType)
 {
     return MediaType\Xml::isMediaType($contentType);
 }
예제 #4
0
파일: Atom.php 프로젝트: 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;
 }