本文整理汇总了PHP中DOMNode::getPrefixFor方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::getPrefixFor方法的具体用法?PHP DOMNode::getPrefixFor怎么用?PHP DOMNode::getPrefixFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::getPrefixFor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encode
public function encode($variable, \DOMNode $node, Type $type)
{
if ($type instanceof AbstractComplexType) {
foreach ($type->getAttributes() as $attribute) {
$val = self::getValueFrom($variable, $attribute->getName());
if ($val !== null) {
if ($attribute->getQualification() == "qualified") {
$attributeNode = $node->ownerDocument->ocreateAttributeNS($attribute->getNs(), $node->getPrefixFor($attribute->getNs()) . ":" . $attribute->getName());
$node->setAttributeNodeNs($attributeNode);
} else {
$attributeNode = $node->ownerDocument->createAttribute($attribute->getName());
$node->setAttributeNode($attributeNode);
}
$this->convertSimplePhpXml($val, $attributeNode, $attribute->getType());
} elseif ($attribute->isRequred()) {
throw new \Exception("Type {$type}, attributo " . $attribute . " non deve essere vuoto");
}
}
if ($type->getBase()) {
$this->encode($variable, $node, $type->getBase());
}
if ($type instanceof ComplexType) {
foreach ($type->getElements() as $element) {
$elementQualified = $element->getQualification() == "qualified";
$newType = $element->getType();
if ($element->getMax() > 1 && ($val = self::tryGetValueFrom($variable, $element->getName())) && (is_array($val) || $val instanceof \Traversable)) {
foreach ($val as $nval) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
$this->encode($nval, $newNode, $newType);
}
} elseif ($element->getMax() > 1 && (is_array($variable) || $variable instanceof \Traversable)) {
foreach ($variable as $nval) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
$this->encode($nval, $newNode, $newType);
}
} else {
$val = self::getValueFrom($variable, $element->getName());
if ($val !== null || $element->isNillable()) {
if ($elementQualified) {
$newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
} else {
$newNode = $node->addChild($element->getName());
}
if ($val === null) {
$newNode->setAttributeNS(self::NS_XSI, $newNode->getPrefixFor(self::NS_XSI) . ":nil", "true");
} else {
$this->encode($val, $newNode, $newType);
}
} elseif ($element->getMin() > 0) {
throw new \Exception($element . " non deve essere vuoto");
}
}
}
}
}
if ($type instanceof SimpleType) {
$this->convertSimplePhpXml($variable, $node, $type);
}
}