예제 #1
0
 /**
  * @param XmlElement $toAppend
  * @param boolean $root
  * @return void
  */
 public function appendChild($toAppend, $root = false)
 {
     if ($root) {
         $node = $this->addChild($toAppend->getName());
         foreach ($toAppend->attributes() as $key => $value) {
             $node->addAttribute($key, $value);
         }
         $node->appendChild($toAppend);
     } else {
         foreach ($toAppend as $name => $tree) {
             $child = $this->addChild($name, $this->_fixContent(strval($tree)));
             foreach ($tree->attributes() as $attrKey => $attrValue) {
                 $child->addAttribute($attrKey, $attrValue);
             }
             $child->appendChild($tree->children());
         }
     }
 }
 /**
  * Asserts that the supplied <tt>XML</tt> represents a valid
  * <tt>*lt;object></tt>.
  * @param XmlElement $xml
  * @throws \NullPointerException if the passed <tt>$xml</tt> is null.
  * @throws \InvalidArgumentException if the <tt>$xml</tt> is invalud.
  * @see \Rhapsody\SetupBundle\Parser\ObjectParser::assert()
  */
 public function assert($xml)
 {
     if ($xml === null) {
         throw new \NullPointerException('Unable to parse: null.');
     }
     if (!$xml instanceof XmlElement) {
         throw new \InvalidArgumentException('Invalid input. ' . get_class($this) . ' expects an XmlElement');
     }
     $name = $xml->getName();
     if (!in_array(strtolower($name), $this->elements)) {
         throw new \InvalidArgumentException('The element: ' . $name . ' was not a valid object-element and could not be parsed by ' . get_class($this) . '.');
     }
     $className = $xml->getAttribute('class');
     $ref = $xml->getAttribute('ref');
     if (empty($className) && empty($ref)) {
         throw new \InvalidArgumentException('An object must have either the "class" or "ref" attributes specified. Could not find either attributes in XML: ' . strval($xml));
     }
 }