Skip to content
Snippets Groups Projects
Commit 0b1572c8 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Evaluate: support to show steps of parsing and evaluation.

Form: Error Message if multiple forms have the same name.
parent 12d16838
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ class Evaluate {
private $endDelimiter = '';
private $endDelimiterLength = 0;
private $sqlKeywords = array('SELECT ', 'INSERT ', 'DELETE ', 'UPDATE ', 'SHOW ');
private $debugStack = array();
public function __construct(Store $store, Database $db, $startDelimiter = '{{', $endDelimiter = '}}') {
......@@ -43,7 +44,7 @@ class Evaluate {
* @param $tokenArray
* @return mixed
*/
public function parseArray($tokenArray) {
public function parseArray($tokenArray, $flagDebug = false) {
$arr = array();
foreach ($tokenArray as $key => $value) {
......@@ -76,6 +77,8 @@ class Evaluate {
while ($posFirstClose !== false) {
$this->debugStack[] = $line . " [$recursion]";
$posMatchOpen = strrpos(substr($line, 0, $posFirstClose), $this->startDelimiter);
if ($posMatchOpen === false) {
throw new \qfq\exceptions\UserException("Missing open delimiter: $line", ERROR_MISSING_OPEN_DELIMITER);
......@@ -86,6 +89,7 @@ class Evaluate {
$match = substr($line, $posMatchOpen + $this->startDelimiterLength, $posFirstClose - $posMatchOpen - $this->startDelimiterLength);
$evaluated = $this->substitute($match);
$this->debugStack[] = $line . " [$recursion]";
// If an array is returned, break everything and return this assoc array.
if (is_array($evaluated)) {
......@@ -150,4 +154,8 @@ 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;
}
public function getDebug() {
return '<pre>' . implode("\n", $this->debugStack) . '</pre>';
}
}
\ No newline at end of file
......@@ -176,7 +176,7 @@ class Form {
$formName = $this->getFormName();
$this->store->setVar(SYSTEM_FORM, $formName, STORE_SYSTEM);
$this->formSpec = $this->eval->parseArray($this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName]));
$this->formSpec = $this->eval->parseArray($this->db->sql("SELECT * FROM Form AS f WHERE f.name LIKE ? AND f.deleted='no'", ROW_EXACT_1, [$formName], 'Form not found or multiple forms with the same name.'));
HelperFormElement::explodeParameter($this->formSpec);
// Clear
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment