Esempio n. 1
0
 /**
  * \private
  *
  * Helper function to create RSS XML elements.
  *
  * This is only for internal use.
  *
  * \param $obj
  *   The object from which to retrieve the value
  *
  * \param $property
  *   The property name
  *
  * \param $tagname
  *   The XML tag name
  *
  * \param $status
  *   Status of the element
  *
  * \param $type
  *   Data type of the element
  *
  * \return
  *   An AnewtXMLDomElement instance, or null.
  */
 public static function _build_rss_element($obj, $property, $tagname, $status, $type)
 {
     if (!$obj->_isset($property)) {
         /* If an optional element not provided it's not a problem... */
         if ($status == ANEWT_RSS_ELEMENT_STATUS_OPTIONAL) {
             return null;
         }
         /* ...but required means required! */
         throw new AnewtException('AnewtRssItem::render(): Required property "%s" not set.', $property);
     }
     $value = $obj->_get($property);
     switch ($type) {
         case ANEWT_RSS_ELEMENT_TYPE_STRING:
             assert('is_string($value);');
             break;
         case ANEWT_RSS_ELEMENT_TYPE_CANONICAL_URL:
             assert('is_string($value);');
             if (str_has_prefix($value, '/')) {
                 /* Fixup relative URL's without a http://hostname.ext/ part */
                 $value = AnewtRequest::canonical_base_url() . $value;
             }
             break;
         case ANEWT_RSS_ELEMENT_TYPE_INTEGER:
             assert('is_int($value);');
             $value = (string) $value;
             break;
         case ANEWT_RSS_ELEMENT_TYPE_DATE:
             assert('$value instanceof AnewtDateTimeAtom;');
             $value = AnewtDateTime::rfc2822($value);
             break;
         default:
             assert('false; // not reached');
             break;
     }
     $element = new AnewtXMLDomElement($tagname);
     $element->append_child(new AnewtXMLDomText($value));
     return $element;
 }