private function parseXml(SimpleXMLElement $xml, PiBX_AST_Tree $ast, $parentObject) { $count = $ast->countChildren(); if (!$xml->children()) { // a leaf node in the XML documents doesn't need to be parsed any further return (string) $xml; } if ($count == 0) { if ($ast instanceof PiBX_AST_Structure) { $newObject = $this->parseStructure($xml, $ast, $parentObject); } else { throw new RuntimeException('Not supported yet'); } } else { $newObject = $parentObject; for ($i = 0; $i < $count; $i++) { $child = $ast->get($i); $name = $child->getName(); $childXml = $xml->{$name}; if ($child instanceof PiBX_AST_Structure) { $newObject = $this->parseStructure($xml->{$name}, $child, $parentObject); } elseif ($child instanceof PiBX_AST_Collection) { $name = $ast->getName(); $list = $this->parseCollection($xml, $child, $parentObject); $setter = $child->getSetMethod(); $parentObject->{$setter}($list); } elseif ($child instanceof PiBX_AST_TypeAttribute) { $newObject = $this->parseTypeAttribute($xml, $child, $parentObject); } else { throw new RuntimeException('Not supported yet'); } } } return $newObject; }
/** * XSD-Choice elements are handled via private variables/constants * * @param PiBX_AST_Tree $tree * @return array The choice constants as strings */ public static function createChoiceConstantsFor(PiBX_AST_Tree $tree) { $childCount = $tree->countChildren(); $name = strtoupper($tree->getName()); $names = array(); for ($i = 0; $i < $childCount; ++$i) { $child = $tree->get($i); $childName = strtoupper($child->getName()); $names[] = $name . '_' . $childName . '_CHOICE'; } return $names; }
public function visitTypeAttributeEnter(PiBX_AST_Tree $tree) { if ($tree->countChildren() == 0) { // base type attribute $attributeName = PiBX_Binding_Names::getAttributeName($tree->getName()); $methodName = PiBX_Binding_Names::getCamelCasedName($tree->getName()); $this->currentClassAttributes .= "\tprivate \$" . $attributeName . ";\n"; $type = $tree->getType(); $methods = "\tpublic function set" . $methodName . "("; if (!PiBX_ParseTree_BaseType::isBaseType($type)) { // complexTypes (i.e. classes) have to be type-hinted // in the method signature. $expectedType = PiBX_Binding_Names::createClassnameFor($type); $methods .= $expectedType . ' '; } $methods .= "\$" . $attributeName . ") {\n"; if ($this->doTypeChecks) { $methods .= $this->typeChecks->getTypeCheckFor($tree->getType(), $attributeName); } $methods .= "\t\t\$this->" . $attributeName . " = \$" . $attributeName . ";\n" . "\t}\n" . "\tpublic function get" . $methodName . "() {\n" . "\t\treturn \$this->" . $attributeName . ";\n" . "\t}\n"; $this->currentClassMethods .= $methods; return false; } else { return true; } }
public function visitTypeAttributeEnter(PiBX_AST_Tree $tree) { if ($tree->countChildren() == 0) { if (PiBX_ParseTree_BaseType::isBaseType($tree->getType())) { $this->xml .= '<value style="' . $tree->getStyle() . '"'; $this->xml .= ' name="' . $tree->getName() . '"'; $getter = PiBX_Binding_Names::createGetterNameFor($tree); $setter = PiBX_Binding_Names::createSetterNameFor($tree); $this->xml .= ' get-method="' . $getter . '"'; $this->xml .= ' set-method="' . $setter . '"'; $this->xml .= '/>'; } else { $this->xml .= '<structure map-as="' . $tree->getType() . '"'; $getter = PiBX_Binding_Names::createGetterNameFor($tree); $setter = PiBX_Binding_Names::createSetterNameFor($tree); $this->xml .= ' get-method="' . $getter . '"'; $this->xml .= ' set-method="' . $setter . '"'; $this->xml .= ' name="' . $tree->getName() . '"'; $this->xml .= '/>'; } return false; } else { return true; } }