function addFillNoValue($text) { $excluded = array(); $rule = excludeText($text, $excluded); $rule = str_replace("[", TEXT_BRACKET_LEFT, $rule); $rule = str_replace("]", TEXT_BRACKET_RIGHT, $rule); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); //echo '<BR/>' . $rule; $rule = includeText($rule, $excluded); $parser = new PHPParser_Parser(new PHPParser_Lexer()); $this->factory = new PHPParser_BuilderFactory(); $this->printer = new PHPParser_PrettyPrinter_Default(); $classextension = prepareClassExtension($text); $rootnode = $this->factory->class(CLASS_GETFILL . "_" . $classextension)->extend(CLASS_BASICFILL); $stmt = new PHPParser_Node_Stmt_Return(new PHPParser_Node_Scalar_String("")); try { //echo $rule . "<br/>"; $stmts = $parser->parse("<?php " . $rule . " ?>"); $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); // fake method call for Q1[1,1] reference if ($stmt->value instanceof PHPParser_Node_Expr_MethodCall) { //print_r($stmt->value); $stmt = new PHPParser_Node_Stmt_Return($stmt->value); } else { //print_r($stmt->value->name); //echo 'hghghghghg'; //$stmt = new PHPParser_Node_Stmt_Return($stmt->value->name->args[0]->value); $stmt = new PHPParser_Node_Stmt_Return($stmt->value->name); } } catch (PHPParser_Error $e) { $this->addErrorMessage(Language::errorFillInvalid()); return; } /* add getFillValue function */ $getfillvalue = $this->factory->method(FUNCTION_GET_FILL_VALUE); $getfillvalue->makePublic(); $getfillvalue->addStmt($stmt); $rootnode->addStmt($getfillvalue); /* get statements */ $stmts = array($rootnode->getNode()); /* generate code */ $fillclass = $this->printer->prettyPrint($stmts); /* return result */ //echo $fillclass . "<hr>"; return $fillclass; }
function getFillValue($variable) { // always redo fills //if ($this->redofills == true) { //if (isset($this->setfillclasses)) { // if (isset($this->setfillclasses[strtoupper(getBasicName($variable))])) { //echo 'reoding: ' . $variable . getSurveyLanguage(); //$this->setFillValue($this->setfillclasses[strtoupper(getBasicName($variable))]); if (!inArray(getBasicName($variable), $this->processedfills) && $this->wasAssigned(getBasicName($variable)) == false) { // only do each fill once! $this->setFillValue(getBasicName($variable)); $this->processedfills[] = getBasicName($variable); } // } //} //} if ($this->getfillclasses) { //echo $variable; $classextension = prepareClassExtension($variable); //echo $this->getfillclasses['"' . strtoupper($variable) . '"']; //echo "<hr>"; //echo CLASS_GETFILL . "_" . $classextension; $getfillclass = $this->loadGetFillClass(CLASS_GETFILL . "_" . $classextension, $this->getfillclasses['"' . strtoupper($variable) . '"']); if ($getfillclass) { //echo 'result: ' . $getfillclass->getFillValue() . "<hr>"; return $getfillclass->getFillValue(); } } return ""; }
function handleFill($text) { $excluded = array(); $rule = excludeText($text, $excluded); $rule = str_replace("[", TEXT_BRACKET_LEFT, $rule); $rule = str_replace("]", TEXT_BRACKET_RIGHT, $rule); // hide module dot notations $rule = hideModuleNotations($rule, TEXT_MODULE_DOT); //echo '<BR/>' . $rule; $rule = includeText($rule, $excluded); $parser = new PHPParser_Parser(new PHPParser_Lexer()); $classextension = prepareClassExtension($text); try { $stmts = $parser->parse("<?php " . $rule . " ?>"); $stmt = $stmts[0]; $stmt = new PHPParser_Node_Arg($stmt); // encapsulate in fake Argument object, since updateVariables looks only at children of entered node $this->updateVariables($stmt); // fake method call for Q1[1,1] reference $cleanup = false; if ($stmt->value instanceof PHPParser_Node_Expr_MethodCall) { $stmt = $stmt->value; $cleanup = true; } else { if (isset($stmt->value->name)) { $stmt = $stmt->value->name; } else { $stmt = $stmt->value; } } } catch (PHPParser_Error $e) { $this->addErrorMessage(Language::errorFillInvalid()); return; } /* get statements */ $stmts = array($stmt); /* generate code */ $fillcall = $this->printer->prettyPrint($stmts); // clean up if ($cleanup) { $fillcall = str_replace(" . (", "", $fillcall); $fillcall = str_replace(" . ])", "]", $fillcall); } /* return result */ //echo $fillclass . "<hr>"; // strip ending ; return substr($fillcall, 0, strlen($fillcall) - 1); }