Commit 0ac8d21f authored by Carsten  Rose's avatar Carsten Rose
Browse files

Evaluate.php: Code rearranged. Doc and Typos fixed. Added parseArray()

parent 7131800f
......@@ -35,8 +35,29 @@ class Evaluate {
}
/**
* Evaluate a whole array.
*
* @param $tokenArray
* @return mixed
*/
public function parseArray($tokenArray) {
$arr = array();
foreach ($tokenArray as $key => $value) {
$arr[$key] = $this->parse($value);
}
return $arr;
}
/**
* Recursive evaluation of 'line'.
* Token to replaces have to be enclosed by '{{' and '}}'
*
* @param $line
* @throws UserException
* @param int $recursion
* @return array|mixed|null|string
* @throws exceptions\UserException
*/
public function parse($line, $recursion = 0) {
......@@ -80,8 +101,9 @@ class Evaluate {
/**
* Tries to substitute $token.
* Token might be
* a) fetched from a store. Syntax: 'form', 'form:C', 'form:SC0', 'form:S:ALNUMX'
* b) Result of a fired SQL statement.
* a) fetch from a store. Syntax: 'form', 'form:C', 'form:SC0', 'form:S:ALNUMX'
* b) a SQL statement to fire
* The token have to be _without_ Delimiter '{{' / '}}'
* If neither a) or b) match, return the token itself, surrounded by single ticks, to emphase that substition failed.
*
* @param $token
......@@ -121,6 +143,4 @@ class Evaluate {
// nothing replaced: put ticks around, to sanatize strings for SQL statements. Nothing to substitute is not a wished situation.
return ($value === false) ? "'" . $token . "'" : $value;
}
}
// Hallo {{SELECT id FROM Form ='{{form}}'}} wird {{SELECT {{SHOW Table}} FROM id={{r}} }} NEW {{SQL}} ENDE
\ No newline at end of file
}
\ No newline at end of file
......@@ -97,6 +97,21 @@ class EvaluateTest extends AbstractDatabaseTest {
}
public function testParseArray() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$data = [
'formName' => 'MyTestForm',
'title' => 'Person: {{SELECT firstname, " ", name FROM person LIMIT 1}} / Employee'
];
$expected = [
'formName' => 'MyTestForm',
'title' => 'Person: John Doe / Employee'
];
$this->assertEquals($expected, $eval->parseArray($data));
}
protected function setUp() {
$this->store = \qfq\store\Store::getInstance('form=TestFormName');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment