Пример #1
0
 /**
  * Instantiates Services_Gnip_Publisher with current class data values
  *
  * @access    public
  * @param     XMLElement               $xml      XML Publisher
  * @return    Services_Gnip_Publisher            Services_Gnip_Publisher object
  */
 function fromXML($xml)
 {
     if ($xml->getName() != "publisher") {
         throw new Exception("expected publisher");
     }
     return new Services_Gnip_Publisher($xml["name"]);
 }
Пример #2
0
 public static function FactoryFromXMLElement(XMLElement $element)
 {
     if ($element->getName() == 'CommonPrefixes') {
         return self::FactoryFromCommonPrefixes($element);
     }
     if ($element->getName() == 'Contents') {
         return self::FactoryFromContents($element);
     }
 }
Пример #3
0
 /**
  * Adds an XMLElement to the `$this->_head` array at a desired position.
  * If no position is given, the object will be added to the end
  * of the `$this->_head` array. If that position is already taken, it will
  * add the object at the next available position.
  *
  * @see toolkit.General#array_find_available_index()
  * @param XMLElement $object
  * @param integer $position
  *  Defaults to null which will put the `$object` at the end of the
  *  `$this->_head`.
  * @param boolean $allowDuplicate
  *  If set to false, make this function check if there is already an XMLElement that as the same name in the head.
  *  Defaults to true. @since Symphony 2.3.2
  * @return integer
  *  Returns the position that the `$object` has been set in the `$this->_head`
  */
 public function addElementToHead(XMLElement $object, $position = null, $allowDuplicate = true)
 {
     // find the right position
     if ($position && isset($this->_head[$position])) {
         $position = General::array_find_available_index($this->_head, $position);
     } elseif (is_null($position)) {
         if (count($this->_head) > 0) {
             $position = max(array_keys($this->_head)) + 1;
         } else {
             $position = 0;
         }
     }
     // check if we allow duplicate
     if (!$allowDuplicate && !empty($this->_head)) {
         $this->removeFromHead($object->getName());
     }
     // append new element
     $this->_head[$position] = $object;
     return $position;
 }
Пример #4
0
 private function getChildrenWithClass(XMLElement &$rootElement, $className, $tagName = null)
 {
     if ($rootElement == null) {
         return null;
     }
     // contains the right css class and the right node name (if any)
     // TODO: Use word bondaries instead of strpos
     if ((!$className || strpos($rootElement->getAttribute('class'), $className) > -1) && (!$tagName || $rootElement->getName() == $tagName)) {
         return $rootElement;
     }
     // recursive search in child elements
     foreach ($rootElement->getChildren() as $key => $child) {
         if (!$child instanceof XMLElement) {
             continue;
         }
         $res = $this->getChildrenWithClass($child, $className, $tagName);
         if ($res != null) {
             return $res;
         }
     }
     return null;
 }