@@ -126,7 +126,7 @@ private function parse($content) {
126126 $ endContent = $ closePos ;
127127 $ subContent = substr ($ content , $ startContent , $ endContent - $ startContent );
128128 $ contentStatement = new Statement ("CONTENT " , $ subContent , []);
129-
129+
130130 //create if statement
131131 $ ifStatement = new Statement ("IF " , [$ contentStatement ], $ setting );
132132 $ statements [] = $ ifStatement ;
@@ -242,44 +242,44 @@ private function parse($content) {
242242 }
243243 }
244244 break ;
245- case 'FOR ' :
246- $ nextPos = strpos ($ content , "{{ " , $ loopPos + 2 );
247- $ closePos = strpos ($ content , "{{ENDFOR}} " , $ loopPos + 2 );
248- if ($ closePos === false ) {
249- throw new Exception ("Syntax error: FOR statement at $ loopPos not closed! " );
250- }
251- $ startCondition = $ loopPos + 6 ;
252- $ endCondition = strpos ($ content , "}} " , $ startCondition );
253- $ setting = explode ("; " , substr ($ content , $ startCondition , $ endCondition - $ startCondition ));
254- if ( sizeof ( $ setting ) != 3 ) {
255- throw new Exception ( " Invalid condition size on FOR on $ loopPos " );
256- }
257- if ( $ nextPos == $ closePos ) {
258- //we have a simple for statement
259- $ startContent = $ endCondition + 2 ;
260- $ endContent = $ closePos ;
261- $ subContent = substr ( $ content , $ startContent , $ endContent - $ startContent ) ;
262- $ contentStatement = new Statement ( " CONTENT " , $ subContent , [] );
263-
264- //create for statement
265- $ forStatement = new Statement ("FOR " , [$ contentStatement ], $ setting );
266- $ statements [] = $ forStatement ;
267- $ pos = $ closePos + 10 ;
268- }
269- else {
270- //the for statement has some inner statements
271- $ innerContent = substr ( $ content , $ endCondition + 2 );
272- $ result = $ this ->parse ($ innerContent );
273- $ endPos = $ result [1 ] + $ endCondition + 2 ;
274- if ($ endPos != strpos ($ content , "{{ENDFOR}} " , $ endPos )) {
275- throw new Exception ("FOR statement not closed correctly at $ endPos! " );
276- }
277- $ forStatement = new Statement ("FOR " , $ result [0 ], $ setting );
278- $ statements [] = $ forStatement ;
279- $ pos = $ endPos + 10 ;
280- }
281- break ;
282- case 'FOREACH ' :
245+ case 'FOR ' :
246+ $ nextPos = strpos ($ content , "{{ " , $ loopPos + 2 );
247+ $ closePos = strpos ($ content , "{{ENDFOR}} " , $ loopPos + 2 );
248+ if ($ closePos === false ) {
249+ throw new Exception ("Syntax error: FOR statement at $ loopPos not closed! " );
250+ }
251+ $ startCondition = $ loopPos + 6 ;
252+ $ endCondition = strpos ($ content , "}} " , $ startCondition );
253+ $ setting = explode ("; " , substr ($ content , $ startCondition , $ endCondition - $ startCondition ));
254+
255+ if ( sizeof ( $ setting ) != 3 ) {
256+ throw new Exception ( " Invalid condition size on FOR on $ loopPos " );
257+ }
258+ if ( $ nextPos == $ closePos ) {
259+ // Simple for loop
260+ $ startContent = $ endCondition + 2 ;
261+ $ endContent = $ closePos ;
262+ $ subContent = substr ( $ content , $ startContent , $ endContent - $ startContent );
263+
264+ $ contentStatement = new Statement ( " CONTENT " , $ subContent , []);
265+ $ forStatement = new Statement ("FOR " , [$ contentStatement ], $ setting );
266+ $ statements [] = $ forStatement ;
267+ $ pos = $ closePos + 10 ;
268+ } else {
269+ // The for statement has some inner statements
270+ $ innerContent = substr ( $ content , $ endCondition + 2 );
271+
272+ $ result = $ this ->parse ($ innerContent );
273+ $ endPos = $ result [1 ] + $ endCondition + 2 ;
274+ if ($ endPos != strpos ($ content , "{{ENDFOR}} " , $ endPos )) {
275+ throw new Exception ("FOR statement not closed correctly at $ endPos! " );
276+ }
277+ $ forStatement = new Statement ("FOR " , $ result [0 ], $ setting );
278+ $ statements [] = $ forStatement ;
279+ $ pos = $ endPos + 10 ;
280+ }
281+ break ;
282+ case 'FOREACH ' :
283283 $ nextPos = strpos ($ content , "{{ " , $ loopPos + 2 );
284284 $ closePos = strpos ($ content , "{{ENDFOREACH}} " , $ loopPos + 2 );
285285 if ($ closePos === false ) {
0 commit comments