@@ -30,27 +30,33 @@ public function spladeHead()
3030 return '{{ app( \'laravel-splade-seo \')->renderHead() }} ' ;
3131 }
3232
33- public function registerTableCellDirective ()
33+ public static function parseTableCellDirectiveExpression ( $ expression ): array
3434 {
35- $ cellDirectiveName = config ( ' splade.blade.table_cell_directive ' );
35+ preg_match ( " /('| \" )(\w+)('| \" )(,)(\s*)(.*)/ " , $ expression , $ matches );
3636
37- Blade::directive ($ cellDirectiveName , function ($ expression ) {
38- preg_match ("/('| \")(\w+)('| \")(,)(\s*)(.*)/ " , $ expression , $ matches );
37+ $ name = trim ($ matches [2 ]);
38+
39+ $ arguments = trim ($ matches [6 ], '\[\] ' );
40+
41+ $ splitted = preg_split ('/\],(\s*)/ ' , $ arguments );
3942
40- $ name = trim ($ matches [2 ]);
43+ $ slotArguments = trim ($ splitted [0 ] ?? '' );
44+ $ slotUses = trim (ltrim ($ splitted [1 ] ?? '' , '[ ' ));
4145
42- $ arguments = trim ( $ matches [ 6 ], ' \[\] ' ) ;
46+ $ slotUses = $ slotUses ? "\$ __env, { $ slotUses }" : "\$ __env " ;
4347
44- $ splitted = preg_split ('/\],(\s*)/ ' , $ arguments );
48+ $ function = "function ( {$ slotArguments }) " ;
49+ $ function .= " use ( {$ slotUses }) " ;
4550
46- $ slotArguments = trim ( $ splitted [ 0 ] ?? '' ) ;
47- $ slotUses = trim ( ltrim ( $ splitted [ 1 ] ?? '' , ' [ ' ));
51+ return [ $ name , $ function ] ;
52+ }
4853
49- $ function = "function ( {$ slotArguments }) " ;
54+ public function registerTableCellDirective ()
55+ {
56+ $ cellDirectiveName = config ('splade.blade.table_cell_directive ' );
5057
51- if ($ slotUses ) {
52- $ function .= " use ( {$ slotUses }) " ;
53- }
58+ Blade::directive ($ cellDirectiveName , function ($ expression ) {
59+ [$ name , $ function ] = BladeDirectives::parseTableCellDirectiveExpression ($ expression );
5460
5561 return "<?php \$__env->slot('spladeTableCell {$ name }', {$ function } { ?> " ;
5662 });
0 commit comments