コード例 #1
0
ファイル: Unmarshaller.php プロジェクト: rocksolid-tn/pibx
 private function parseTypeAttribute(SimpleXMLElement $xml, PiBX_AST_TypeAttribute $ast, $parentObject)
 {
     $name = $ast->getName();
     if ($ast->getStyle() == 'element') {
         $value = (string) $xml->{$name};
     } elseif ($ast->getStyle() == 'attribute') {
         $attributes = $xml->attributes();
         $value = (string) $attributes[$name];
     }
     $setter = $ast->getSetMethod();
     $parentObject->{$setter}($value);
     return $parentObject;
 }
コード例 #2
0
ファイル: Marshaller.php プロジェクト: rocksolid-tn/pibx
 private function marshalTypeAttribute($object, PiBX_AST_TypeAttribute $ast)
 {
     if ($ast->getStyle() == 'element') {
         $getter = $ast->getGetMethod();
         $value = $object->{$getter}();
         $newNode = $this->dom->createTextNode($value);
         $this->currentDomNode->appendChild($newNode);
     } elseif ($ast->getStyle() == 'attribute') {
         $getter = $ast->getGetMethod();
         $name = $ast->getName();
         $value = $object->{$getter}();
         if ($value != '') {
             // TODO check for "optional" attribute in binding.
             $this->parentDomNode->setAttribute($name, $value);
         }
         // in marshalObject() a child is added everytime.
         // no matter what type it is ("attribute" or "element"),
         // so we can just remove it here
         $this->parentDomNode->removeChild($this->currentDomNode);
     } else {
         throw new RuntimeException('Invalid TypeAttribute style "' . $ast->getStyle() . '"');
     }
 }