@@ -21,23 +21,29 @@ protected function isDisplay(string $expression)
2121 // $this->console("expression $expression === $result");
2222 return $ result ;
2323 }
24- protected function executeExpression (string $ expression ,int $ addrowqty =0 ,string $ evaluationTime ='' ): mixed
24+ protected function executeExpression (string $ expression ,int $ addrowqty =0 ,string $ evaluationTime ='' , $ isstring = false ): mixed
2525 {
2626 // $this->console( "executeExpression: $expression");
27- $ value = $ this ->parseExpression ($ expression ,$ addrowqty ,$ evaluationTime );
27+ $ value = $ this ->parseExpression ($ expression ,$ addrowqty ,$ evaluationTime, true );
2828
2929 //special result, direct return raw value
3030 if (gettype ($ value )=='object ' || gettype ($ value )=='array ' )
3131 {
3232 return $ value ;
3333 }
3434 //it consist of string, use concate instead of maths operation
35+ // if($isstring){
36+
37+ // }
38+ // $value = str_replace('+',' . ',$value);
39+ //
40+ $ value = str_replace (["<{{ " ,"}}> " ],'" ' ,$ value );
3541 if (str_contains ($ value ,'" ' ) || str_contains ($ value ,"' " ))
3642 {
37- $ value = str_replace ('+ ' ,' . ' ,$ value );
43+ $ findquotepattern = '/\+(?=(?:[^"]*"[^"]*")*[^"]*\Z)/ ' ;
44+ $ value = preg_replace ($ findquotepattern , '. ' , $ value );
3845 }
3946
40-
4147 $ evalstr = "return $ value; " ;
4248 // $this->console( $evalstr);
4349 try {
@@ -52,7 +58,7 @@ protected function executeExpression(string $expression,int $addrowqty=0,string
5258 }
5359 }
5460
55- protected function parseExpression (string $ expression ,int $ addrowqty =0 ,string $ evaluationTime ='' ): mixed
61+ protected function parseExpression (string $ expression ,int $ addrowqty =0 ,string $ evaluationTime ='' , $ specialtag = false ): mixed
5662 {
5763 $ value = $ expression ;
5864 $ fieldpattern = '/\$F{(.*?)}/ ' ;
@@ -64,7 +70,7 @@ protected function parseExpression(string $expression,int $addrowqty=0,string $e
6470 preg_match_all ($ fieldpattern , $ value , $ matchfield );
6571 preg_match_all ($ varpattern , $ value , $ matchvar );
6672 preg_match_all ($ parapattern , $ value , $ matchpara );
67-
73+
6874 $ fieldstrings = $ matchfield [0 ];
6975 $ fieldnames = $ matchfield [1 ];
7076 $ parastrings = $ matchpara [0 ];
@@ -73,18 +79,18 @@ protected function parseExpression(string $expression,int $addrowqty=0,string $e
7379 $ varnames = $ matchvar [1 ];
7480 // $this->console($expression);
7581 foreach ($ fieldnames as $ f => $ fieldname )
76- {
77- $ data = $ this ->getFieldValue ($ fieldname ,$ addrowqty ,$ evaluationTime );
82+ {
83+ $ data = $ this ->getFieldValue ($ fieldname ,$ addrowqty ,$ evaluationTime, $ specialtag );
7884 $ value = str_replace ($ fieldstrings [$ f ], $ data ,$ value );
7985 }
8086 foreach ($ varnames as $ v => $ varname )
8187 {
82- $ data = $ this ->getVariableValue ($ varname ,$ evaluationTime );
88+ $ data = $ this ->getVariableValue ($ varname ,$ evaluationTime, $ specialtag );
8389 $ value = str_replace ($ varstrings [$ v ], $ data ,$ value );
8490 }
8591 foreach ($ paranames as $ p => $ paraname )
8692 {
87- $ data = $ this ->getParameterValue ($ paraname ,$ evaluationTime );
93+ $ data = $ this ->getParameterValue ($ paraname ,$ evaluationTime, $ specialtag );
8894 if (gettype ($ data )=='array ' || gettype ($ data )=='object ' )
8995 {
9096 return $ data ;
@@ -100,26 +106,32 @@ protected function overrideJavaFunctions(string $expression,string $evaluationTi
100106 $ expression = str_replace ('new java.util.Date() ' ,'" ' .date ('Y-m-d H:i:s ' ).'" ' ,$ expression );
101107 return $ expression ;
102108 }
103- protected function getFieldValue (string $ name ,int $ addrowqty =0 ,string $ evaluationTime ='' )
109+ protected function getFieldValue (string $ name ,int $ addrowqty =0 ,string $ evaluationTime ='' , $ specialtag = false )
104110 {
105111 $ rowno = $ this ->currentRow +$ addrowqty - $ this ->reducerowno ;
106112 $ datatype = $ this ->fields [$ name ]['datatype ' ];
107113 if (isset ($ this ->rows [$ rowno ]))
108114 {
109115 $ row =$ this ->rows [$ rowno ] ;
110- $ value =$ row [$ name ];
116+ if (isset ($ row [$ name ])) {
117+ $ value =$ row [$ name ];
118+ }
119+ else {
120+ echo "field not exist : " .$ name ."<br/> " ;
121+ die;
122+ }
111123 }
112124 else
113125 {
114126 $ value =null ;
115127 }
116128
117- $ value = $ this ->escapeIfRequire ($ value ,$ datatype );
129+ $ value = $ this ->escapeIfRequire ($ value ,$ datatype, $ specialtag );
118130 return $ value ;
119131 }
120132
121133
122- protected function getParameterValue (string $ key ,string $ evaluationTime ='' )
134+ protected function getParameterValue (string $ key ,string $ evaluationTime ='' , $ specialtag = false )
123135 {
124136 $ value =null ;
125137 if (!isset ($ this ->parameters [$ key ]))
@@ -155,12 +167,12 @@ protected function getParameterValue(string $key,string $evaluationTime='')
155167 $ value = $ this ->parameters [$ key ]['value ' ];
156168 }
157169 $ datatype = $ this ->parameters [$ key ]['datatype ' ]??'string ' ;
158- $ value = $ this ->escapeIfRequire ($ value ,$ datatype );
170+ $ value = $ this ->escapeIfRequire ($ value ,$ datatype, $ specialtag );
159171 return $ value ;
160172 }
161173
162174
163- protected function getVariableValue ($ key ,string $ evaluationTime ='' )
175+ protected function getVariableValue ($ key ,string $ evaluationTime ='' , $ specialtag = false )
164176 {
165177 // echo "\n getVariableValue $key: \n";
166178 $ datatype = "number " ;//by default all datatype is number, unless variable class defined
@@ -226,7 +238,7 @@ protected function getVariableValue($key,string $evaluationTime='')
226238
227239
228240 // echo "\nvar $key type = $datatype, data = $data \n";
229- $ result = $ this ->escapeIfRequire ($ data ,$ datatype );
241+ $ result = $ this ->escapeIfRequire ($ data ,$ datatype, $ specialtag );
230242 break ;
231243 }
232244 return $ result ;
@@ -238,8 +250,10 @@ protected function getVariableValue($key,string $evaluationTime='')
238250 * @param mixed $datatype string, number, boolean or null
239251 * @return mixed $data string or number value;
240252 */
241- public function escapeIfRequire (mixed $ value ,mixed $ datatype ): mixed
253+ public function escapeIfRequire (mixed $ value ,mixed $ datatype, $ specialtag ): mixed
242254 {
255+ $ opentag = $ specialtag ? '<{{ ' : '" ' ;
256+ $ closetag = $ specialtag ? '}}> ' : '" ' ;
243257 if (gettype ($ datatype )=='NULL ' )
244258 {
245259 $ datatype = 'string ' ;
@@ -265,7 +279,7 @@ public function escapeIfRequire(mixed $value,mixed $datatype): mixed
265279 }
266280 $ data = addslashes ($ value );
267281 $ data = str_replace ('$ ' ,'\$ ' ,$ data );
268- $ data = ' " ' .$ data .' " ' ;
282+ $ data = $ opentag .$ data .$ closetag ;
269283 break ;
270284 }
271285 return (string ) $ data ;
0 commit comments