@@ -55,6 +55,7 @@ public static function composePHPRender(Context $context, string $code): string
5555 $ runtime = Runtime::class;
5656 $ helperOptions = HelperOptions::class;
5757 $ safeStringClass = SafeString::class;
58+ $ runtimeContext = RuntimeContext::class;
5859 $ helpers = Exporter::helpers ($ context );
5960 $ partials = implode (", \n" , $ context ->partialCode );
6061
@@ -63,17 +64,18 @@ public static function composePHPRender(Context $context, string $code): string
6364 use {$ runtime } as LR;
6465 use {$ safeStringClass };
6566 use {$ helperOptions };
67+ use {$ runtimeContext };
6668 return function ( \$in = null, array \$options = []) {
6769 \$helpers = $ helpers;
6870 \$partials = [ $ partials];
69- \$cx = [
70- ' helpers' => isset( \$options['helpers']) ? array_merge( \$helpers, \$options['helpers']) : \$helpers,
71- ' partials' => isset( \$options['partials']) ? array_merge( \$partials, \$options['partials']) : \$partials,
72- ' scopes' => [],
73- 'sp_vars' => isset( \$options['data']) ? array_merge(['root' => \$in], \$options['data']) : ['root' => \$in],
74- 'blparam' => [],
75- 'partialid' => 0,
76- ] ;
71+ \$cx = new RuntimeContext(
72+ helpers: isset( \$options['helpers']) ? array_merge( \$helpers, \$options['helpers']) : \$helpers,
73+ partials: isset( \$options['partials']) ? array_merge( \$partials, \$options['partials']) : \$partials,
74+ scopes: [],
75+ spVars: isset( \$options['data']) ? array_merge(['root' => \$in], \$options['data']) : ['root' => \$in],
76+ blParam: [],
77+ partialId: 0,
78+ ) ;
7779 {$ context ->ops ['op_start ' ]}' $ code' {$ context ->ops ['op_end ' ]}
7880 };
7981 VAREND ;
@@ -166,18 +168,18 @@ protected static function getVariableName(Context $context, array $var, ?array $
166168
167169 [$ levels , $ spvar , $ var ] = Expression::analyze ($ var );
168170 $ exp = Expression::toString ($ levels , $ spvar , $ var );
169- $ base = $ spvar ? "\$cx['sp_vars'] " : '$in ' ;
171+ $ base = $ spvar ? "\$cx->spVars " : '$in ' ;
170172
171173 // change base when trace to parent
172174 if ($ levels > 0 ) {
173175 if ($ spvar ) {
174176 $ base .= str_repeat ("['_parent'] " , $ levels );
175177 } else {
176- $ base = "\$cx[' scopes'] [count( \$cx[' scopes'] )- $ levels] " ;
178+ $ base = "\$cx-> scopes[count( \$cx-> scopes)- $ levels] " ;
177179 }
178180 }
179181
180- if ((empty ( $ var) || (count ( $ var) == 0 ) || (( $ var [0 ] === null ) && ( count ($ var ) == 1 ))) && ( $ lookup === null ) ) {
182+ if ((! $ var || ($ var [0 ] === null && count ($ var ) == 1 )) && $ lookup === null ) {
181183 return [$ base , $ exp ];
182184 }
183185
@@ -295,7 +297,7 @@ public static function inline(Context $context, array $vars): string
295297 protected static function invertedSection (Context $ context , array $ vars ): string
296298 {
297299 $ v = static ::getVariableName ($ context , $ vars [0 ]);
298- return "{$ context ->ops ['cnd_start ' ]}( " . static ::getFuncName ($ context , 'isec ' , '^ ' . $ v [1 ]) . "\$ cx, {$ v [0 ]})) {$ context ->ops ['cnd_then ' ]}" ;
300+ return "{$ context ->ops ['cnd_start ' ]}( " . static ::getFuncName ($ context , 'isec ' , '^ ' . $ v [1 ]) . "{$ v [0 ]})) {$ context ->ops ['cnd_then ' ]}" ;
299301 }
300302
301303 /**
@@ -365,11 +367,11 @@ protected static function blockBegin(Context $context, array $vars): string
365367 case 'if ' :
366368 $ includeZero = (isset ($ vars ['includeZero ' ][1 ]) && $ vars ['includeZero ' ][1 ]) ? 'true ' : 'false ' ;
367369 return "{$ context ->ops ['cnd_start ' ]}( " . static ::getFuncName ($ context , 'ifvar ' , $ v [1 ])
368- . "\$ cx, {$ v [0 ]}, {$ includeZero })) {$ context ->ops ['cnd_then ' ]}" ;
370+ . "{$ v [0 ]}, {$ includeZero })) {$ context ->ops ['cnd_then ' ]}" ;
369371 case 'unless ' :
370372 $ includeZero = (isset ($ vars ['includeZero ' ][1 ]) && $ vars ['includeZero ' ][1 ]) ? 'true ' : 'false ' ;
371373 return "{$ context ->ops ['cnd_start ' ]}(! " . static ::getFuncName ($ context , 'ifvar ' , $ v [1 ])
372- . "\$ cx, {$ v [0 ]}, {$ includeZero })) {$ context ->ops ['cnd_then ' ]}" ;
374+ . "{$ v [0 ]}, {$ includeZero })) {$ context ->ops ['cnd_then ' ]}" ;
373375 case 'each ' :
374376 return static ::section ($ context , $ vars , true );
375377 case 'with ' :
@@ -495,7 +497,7 @@ protected static function compileLookup(Context $context, array &$vars, bool $ra
495497 $ sep = $ nosep ? '' : $ context ->ops ['separator ' ];
496498 $ ex = $ nosep ? ', 1 ' : '' ;
497499
498- return $ sep . static ::getFuncName ($ context , $ raw ? 'raw ' : 'encq ' , $ v [1 ]) . "\$ cx, {$ v [0 ]}$ ex) {$ sep }" ;
500+ return $ sep . static ::getFuncName ($ context , $ raw ? 'raw ' : 'encq ' , $ v [1 ]) . "{$ v [0 ]}$ ex) {$ sep }" ;
499501 }
500502
501503 /**
@@ -508,7 +510,7 @@ protected static function compileLookup(Context $context, array &$vars, bool $ra
508510 protected static function compileOutput (Context $ context , string $ variable , string $ expression , bool $ raw ): string
509511 {
510512 $ sep = $ context ->ops ['separator ' ];
511- return $ sep . static ::getFuncName ($ context , $ raw ? 'raw ' : 'encq ' , $ expression ) . "\$ cx, $ variable) $ sep " ;
513+ return $ sep . static ::getFuncName ($ context , $ raw ? 'raw ' : 'encq ' , $ expression ) . "$ variable) $ sep " ;
512514 }
513515
514516 /**
0 commit comments