public function visitStructureEnter(PiBX_AST_Tree $tree) { $structureType = $tree->getStructureType(); if ($structureType === PiBX_AST_StructureType::CHOICE()) { $name = $tree->getParent()->getName(); $attributeName = $name . 'Select'; $this->currentClassAttributes .= "\tprivate \$" . $attributeName . " = -1;\n"; $constantNames = PiBX_Binding_Names::createChoiceConstantsFor($tree); $i = 0; foreach ($constantNames as $constant) { $this->currentClassAttributes .= "\tprivate \${$constant} = {$i};\n"; ++$i; } $methodName = ucfirst($attributeName); $methods = "\tprivate function set{$methodName}(\$choice) {\n" . "\t\tif (\$this->{$attributeName} == -1) {\n" . "\t\t\t\$this->{$attributeName} = \$choice;\n" . "\t\t} elseif (\$this->{$attributeName} != \$choice) {\n" . "\t\t\tthrow new RuntimeException('Need to call clear{$methodName}() before changing existing choice');\n" . "\t\t}\n" . "\t}\n"; $methods .= "\tpublic function clear{$methodName}() {\n" . "\t\t\$this->{$attributeName} = -1;\n" . "\t}\n"; $this->currentClassMethods .= $methods; } return true; }