/** * 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 visitEnumerationEnter(PiBX_AST_Tree $tree) { $enumName = $tree->getName(); if ($tree->getParent() == null) { // at the moment separate enums are not supported, yet. //$this->classAppendix .= 'class b_' . $this->currentClassName . '_' . ucfirst($enumName) . " {\n"; return false; } $attributeName = PiBX_Binding_Names::getAttributeName($tree->getName()); $methodName = PiBX_Binding_Names::getCamelCasedName($tree->getName()); $this->currentClassAttributes .= "\tprivate \$" . $attributeName . ";\n"; $methods = "\tpublic function set" . $methodName . "(\$" . $attributeName . ") {\n"; if ($this->doTypeChecks) { // to do a type check for enums // all possible values have to be fetched $valueCount = $tree->countChildren(); $conditionValues = array(); for ($i = 0; $i < $valueCount; $i++) { $valueAst = $tree->get($i); $conditionValues[] = $valueAst->getName(); } $ifConditions = "(\$" . $attributeName . " != '" . implode("') || (\$" . $attributeName . " != '", $conditionValues) . "')"; $listOfValues = '"' . implode('", "', $conditionValues) . '"'; $methods .= "\t\tif ("; $methods .= $ifConditions . ") {\n" . "\t\t\tthrow new InvalidArgumentException('Unexpected value \"' . \$" . $attributeName . " . '\". Expected is one of the following: " . $listOfValues . ".');\n" . "\t\t}\n"; } $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 true; }