35
35
* @copyright Copyright (c) 2016-2024 Jorge Patricio Castro Castillo MIT License.
36
36
* Don't delete this comment, its part of the license.
37
37
* Part of this code is based in the work of Laravel PHP Components.
38
- * @version 4.15.1
38
+ * @version 4.16
39
39
* @link https://github.com/EFTEC/BladeOne
40
40
*/
41
41
class BladeOne
42
42
{
43
43
//<editor-fold desc="fields">
44
- public const VERSION = '4.15.2 ' ;
44
+ public const VERSION = '4.16 ' ;
45
45
/** @var int BladeOne reads if the compiled file has changed. If it has changed,then the file is replaced. */
46
46
public const MODE_AUTO = 0 ;
47
47
/** @var int Then compiled file is always replaced. It's slow and it's useful for development. */
@@ -52,6 +52,10 @@ class BladeOne
52
52
public const MODE_DEBUG = 5 ;
53
53
/** @var array Hold dictionary of translations */
54
54
public static array $ dictionary = [];
55
+ /** @var string It is used to mark the start of the stack (regexp). This value must not be used for other purposes */
56
+ public string $ escapeStack0 = '-#1Z#-#2B# ' ;
57
+ /** @var string It is used to mark the end of the stack (regexp). This value must not be used for other purposes */
58
+ public string $ escapeStack1 = '#3R#-#4X#- ' ;
55
59
/** @var string PHP tag. You could use < ?php or < ? (if shorttag is active in php.ini) */
56
60
public string $ phpTag = '<?php ' ; // hello hello hello.
57
61
/** @var string this line is used to easily echo a value */
@@ -766,7 +770,7 @@ public function runString($string, $data = []): string
766
770
$ this ->showError ('runString ' , $ lastError ['message ' ] . ' ' . $ lastError ['type ' ], true );
767
771
return '' ;
768
772
}
769
- return \ob_get_clean ();
773
+ return $ this -> postRun ( \ob_get_clean () );
770
774
}
771
775
772
776
/**
@@ -1272,13 +1276,13 @@ protected function runInternal(string $view, $variables = [], $forced = false, $
1272
1276
}
1273
1277
$ result = $ this ->compile ($ view , $ forced );
1274
1278
if (!$ this ->isCompiled ) {
1275
- return $ this ->evaluateText ($ result , $ this ->variables );
1279
+ return $ this ->postRun ( $ this -> evaluateText ($ result , $ this ->variables ) );
1276
1280
}
1277
1281
} elseif ($ view ) {
1278
1282
$ this ->fileName = $ view ;
1279
1283
}
1280
1284
$ this ->isRunFast = $ runFast ;
1281
- return $ this ->evaluatePath ($ this ->getCompiledFile (), $ this ->variables );
1285
+ return $ this ->postRun ( $ this -> evaluatePath ($ this ->getCompiledFile (), $ this ->variables ) );
1282
1286
}
1283
1287
1284
1288
protected function evalComposer ($ view ): void
@@ -2180,6 +2184,33 @@ public function run($view = null, $variables = []): string
2180
2184
return $ this ->runInternal ($ view , $ variables , $ forced , $ runFast );
2181
2185
}
2182
2186
2187
+ /**
2188
+ * It executes a post run execution. It is used to display the stacks.
2189
+ * @noinspection PhpVariableIsUsedOnlyInClosureInspection
2190
+ */
2191
+ protected function postRun (?string $ string )
2192
+ {
2193
+ if (!$ string ) {
2194
+ return $ string ;
2195
+ }
2196
+ if (strpos ($ string , $ this ->escapeStack0 ) === false ) {
2197
+ // nothing to post run
2198
+ return $ string ;
2199
+ }
2200
+ $ me = $ this ;
2201
+ $ result = preg_replace_callback ('/ ' . $ this ->escapeStack0 . '\s?([A-Za-z0-9_:() ,*.@$]+)\s? ' . $ this ->escapeStack1 . '/u ' ,
2202
+ static function ($ matches ) use ($ me ) {
2203
+ $ l0 = strlen ($ me ->escapeStack0 );
2204
+ $ l1 = strlen ($ me ->escapeStack1 );
2205
+ $ item = trim (is_array ($ matches ) ? substr ($ matches [0 ], $ l0 , -$ l1 ) : substr ($ matches , $ l0 , -$ l1 ));
2206
+ $ items = explode (', ' , $ item );
2207
+ return $ me ->yieldPushContent ($ items [0 ], $ items [1 ] ?? null );
2208
+ //return is_array($r) ? $flagtxt . json_encode($r) : $flagtxt . $r;
2209
+ }, $ string );
2210
+ // we returned the escape character.
2211
+ return $ result ;
2212
+ }
2213
+
2183
2214
/**
2184
2215
* It sets the current view<br>
2185
2216
* This value is cleared when it is used (method run).<br>
@@ -2947,6 +2978,7 @@ protected function getEchoMethods(): array
2947
2978
});
2948
2979
return $ methods ;
2949
2980
}
2981
+
2950
2982
/**
2951
2983
* Compile Blade components that start with "x-".
2952
2984
*
@@ -2966,36 +2998,32 @@ protected function compileComponents($value)
2966
2998
*
2967
2999
* @return string
2968
3000
*/
2969
-
2970
3001
$ callback = function ($ match ) {
2971
-
2972
- if (static ::contains ($ match [0 ], 'x- ' )) {
2973
- $ match [4 ] = $ this ->compileComponents ( $ match [4 ]);
3002
+ if (static ::contains ($ match [0 ], 'x- ' )) {
3003
+ $ match [4 ] = $ this ->compileComponents ($ match [4 ]);
2974
3004
}
2975
3005
$ paramsCompiled = $ this ->parseParams ($ match [2 ]);
2976
- $ str = "('components. " .$ match [1 ]."', " .$ paramsCompiled .") " ;
2977
-
2978
- return self ::compileComponent ($ str ).$ match [4 ].self ::compileEndComponent ();
3006
+ $ str = "('components. " . $ match [1 ] . "', " . $ paramsCompiled . ") " ;
3007
+ return self ::compileComponent ($ str ) . $ match [4 ] . self ::compileEndComponent ();
2979
3008
};
2980
3009
return preg_replace_callback ('/<x-([a-z0-9.-]+)(\s[^>]*)?(>((?:(?!<\/x-\1>).)*)<\/x-\1>|\/>)/ms ' , $ callback , $ value );
2981
-
2982
3010
}
2983
3011
2984
3012
protected function parseParams ($ params ): string
2985
3013
{
2986
3014
preg_match_all ('/([a-z-0-9:]*?)\s*?=\s*?(.+?)(\s|$)/ms ' , $ params , $ matches );
2987
3015
$ paramsCompiled = [];
2988
3016
foreach ($ matches [1 ] as $ i => $ key ) {
2989
- $ value = str_replace ('" ' ,'' ,$ matches [2 ][$ i ]);
3017
+ $ value = str_replace ('" ' , '' , $ matches [2 ][$ i ]);
2990
3018
//its php code
2991
- if (self ::startsWith ($ key , ': ' )) {
3019
+ if (self ::startsWith ($ key , ': ' )) {
2992
3020
$ key = substr ($ key , 1 );
2993
- $ paramsCompiled [] = '" ' . $ key . '" ' . '=> ' . $ value ;
3021
+ $ paramsCompiled [] = '" ' . $ key . '" ' . '=> ' . $ value ;
2994
3022
continue ;
2995
3023
}
2996
- $ paramsCompiled [] = '" ' . $ key . '" ' . '=> ' .'" ' . $ value . '" ' ;
3024
+ $ paramsCompiled [] = '" ' . $ key . '" ' . '=> ' . '" ' . $ value . '" ' ;
2997
3025
}
2998
- return '[ ' . implode (', ' ,$ paramsCompiled ). '] ' ;
3026
+ return '[ ' . implode (', ' , $ paramsCompiled ) . '] ' ;
2999
3027
}
3000
3028
3001
3029
/**
@@ -4161,7 +4189,12 @@ protected function compileViewName($expression): string
4161
4189
*/
4162
4190
protected function compileStack ($ expression ): string
4163
4191
{
4164
- return $ this ->phpTagEcho . "\$this->yieldPushContent $ expression; ?> " ;
4192
+ return $ this ->phpTagEcho . " \$this->CompileStackFinal $ expression; ?> " ;
4193
+ }
4194
+
4195
+ public function CompileStackFinal ($ a = null , $ b = null ): string
4196
+ {
4197
+ return $ this ->escapeStack0 . $ a . ', ' . $ b . $ this ->escapeStack1 ;
4165
4198
}
4166
4199
4167
4200
/**
0 commit comments