Commit 843a3ee2 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Constants: add some comments, added GFX_INFO

Evaluate: add support to show parse/replace actions
parent 38b6701a
......@@ -217,8 +217,8 @@ const SYSTEM_FORM_ELEMENT_MESSAGE = 'formElementMessage'; // '<columnname of cur
//const SYSTEM_FORM_ELEMENT_DEF = 'formElementDefinition'; // Type: SANATIZE_ALL / AssocArray. Formelement which are processed at the moment. Useful for error reporting.
//const SYSTEM_FORM_ELEMENT_FIELD = 'formElementField'; // Type: SANATIZE_ALNUMX / String. Fieldname of processed Formelement. Useful for error reporting.
const SIP_SIP = CLIENT_SIP;
const SIP_RECORD_ID = CLIENT_RECORD_ID;
const SIP_SIP = CLIENT_SIP; // s
const SIP_RECORD_ID = CLIENT_RECORD_ID; // r
const SIP_FORM = CLIENT_FORM;
const SIP_URLPARAM = 'urlparam';
// FURTHER: all extracted params from 'urlparam
......@@ -228,3 +228,5 @@ const SIP_URLPARAM = 'urlparam';
// FORMELEMENT - copy of all formElements of processed form
//const DEF_FORM_ELEMENT_ID = 'id';
const GFX_INFO = 'typo3conf/ext/qfq/Resources/Public/icons/note.gif';
\ No newline at end of file
......@@ -26,7 +26,8 @@ class Evaluate {
private $endDelimiter = '';
private $endDelimiterLength = 0;
private $sqlKeywords = array('SELECT ', 'INSERT ', 'DELETE ', 'UPDATE ', 'SHOW ');
private $debugStack = array();
// private $debugStack = array();
public function __construct(Store $store, Database $db, $startDelimiter = '{{', $endDelimiter = '}}') {
......@@ -44,14 +45,14 @@ class Evaluate {
* @param $tokenArray
* @return mixed
*/
public function parseArray($tokenArray, $flagDebug = false) {
public function parseArray($tokenArray, &$debugStack = array()) {
$arr = array();
foreach ($tokenArray as $key => $value) {
if (is_array($value)) {
$arr[] = $this->parseArray($value);
} else {
$arr[$key] = $this->parse($value);
$arr[$key] = $this->parse($value, 0, $debugStack);
}
}
......@@ -60,53 +61,65 @@ class Evaluate {
/**
* Recursive evaluation of 'line'.
* Token to replaces have to be enclosed by '{{' and '}}'
*
* Token to replace have to be enclosed by '{{' and '}}'
*
* @param $line
* @param int $recursion
* @return array|mixed|null|string
* @throws UserException
*/
public function parse($line, $recursion = 0) {
public function parse($line, $recursion = 0, &$debugStack = array()) {
$flagTokenReplaced = false;
if ($recursion > 4) {
throw new qfq\UserException("Recursion too deep: $line", ERROR_RECURSION_TOO_DEEP);
}
$posFirstClose = strpos($line, $this->endDelimiter);
$result = $line;
while ($posFirstClose !== false) {
$debugIndent = str_repeat(' ', $recursion);
$debugLocal[] = $debugIndent . "#Parse: '$result'";
$this->debugStack[] = $line . " [$recursion]";
$posFirstClose = strpos($result, $this->endDelimiter);
$posMatchOpen = strrpos(substr($line, 0, $posFirstClose), $this->startDelimiter);
while ($posFirstClose !== false) {
$flagTokenReplaced = true;
$posMatchOpen = strrpos(substr($result, 0, $posFirstClose), $this->startDelimiter);
if ($posMatchOpen === false) {
throw new \qfq\UserException("Missing open delimiter: $line", ERROR_MISSING_OPEN_DELIMITER);
throw new \qfq\UserException("Missing open delimiter: $result", ERROR_MISSING_OPEN_DELIMITER);
}
$pre = substr($line, 0, $posMatchOpen);
$post = substr($line, $posFirstClose + $this->endDelimiterLength);
$match = substr($line, $posMatchOpen + $this->startDelimiterLength, $posFirstClose - $posMatchOpen - $this->startDelimiterLength);
$pre = substr($result, 0, $posMatchOpen);
$post = substr($result, $posFirstClose + $this->endDelimiterLength);
$match = substr($result, $posMatchOpen + $this->startDelimiterLength, $posFirstClose - $posMatchOpen - $this->startDelimiterLength);
$evaluated = $this->substitute($match);
$this->debugStack[] = $line . " [$recursion]";
$debugLocal[] = $debugIndent . "#Replace: '$match'";
$debugLocal[] = $debugIndent . "#By: '$evaluated'";
// If an array is returned, break everything and return this assoc array.
if (is_array($evaluated)) {
return $evaluated;
$result = $evaluated;
break;
}
// More to substitute in the new evaluated result? Start recursion just with the new result..
if (strpos($evaluated, $this->endDelimiter) !== false) {
$evaluated = $this->parse($evaluated, $recursion + 1);
}
$evaluated = $this->parse($evaluated, $recursion + 1, $debugLocal);
}
$line = $pre . $evaluated . $post;
$posFirstClose = strpos($line, $this->endDelimiter);
$result = $pre . $evaluated . $post;
$posFirstClose = strpos($result, $this->endDelimiter);
}
if ($flagTokenReplaced === true) {
$debugLocal[] = $debugIndent . "#Final: " . is_array($result) ? "array(" . count($result) .")" : "'$result'" ;
$debugStack = $debugLocal;
}
return $line;
return $result;
}
/**
......
Markdown is supported
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