@@ -135,19 +135,7 @@ private function resolveContent(View $view): string
135135        $ path$ viewgetPath ();
136136
137137        if  (! str_ends_with ($ path'.php ' )) {
138-             ob_start ();
139- 
140-             try  {
141-                 // TODO: find a better way of dealing with views that declare strict types 
142-                 $ pathstr_replace ('declare(strict_types=1); ' , '' , $ path
143- 
144-                 /** @phpstan-ignore-next-line */ 
145-                 eval ('?> '  . $ path'<?php ' );
146-             } catch  (ParseError 
147-                 return  $ path
148-             }
149- 
150-             return  ob_get_clean ();
138+             return  $ this evalContentIsolated ($ view$ path
151139        }
152140
153141        $ discoveryLocations$ this kernel ->discoveryLocations ;
@@ -161,7 +149,7 @@ private function resolveContent(View $view): string
161149            throw  new  Exception ("View  {$ path not found " );
162150        }
163151
164-         return  $ this resolveContentIsolated ($ path $ view -> getData () );
152+         return  $ this resolveContentIsolated ($ view $ path 
165153    }
166154
167155    private  function  resolveViewComponent (GenericElement $ elementViewComponent 
@@ -239,9 +227,9 @@ private function renderCollectionElement(View $view, CollectionElement $collecti
239227    private  function  renderViewComponent (View $ viewViewComponent $ viewComponentGenericElement $ elementstring 
240228    {
241229        $ renderedContentpreg_replace_callback (
242-             pattern: '/<x-slot\s*(name="(?<name>\w+)")?\s*\/>/ ' ,
230+             pattern: '/<x-slot\s*(name="(?<name>\w+)")?(( \s*\/>)|><\/x-slot>) / ' ,
243231            callback: function  ($ matchesuse  ($ view$ element
244-                 $ name$ matches'name ' ] ??  'slot ' ;
232+                 $ name$ matches'name ' ] ?:  'slot ' ;
245233
246234                $ slot$ elementgetSlot ($ name
247235
@@ -306,14 +294,53 @@ private function renderGenericElement(View $view, GenericElement $element): stri
306294        return  "< {$ elementgetTag ()}{$ attributes> {$ content</ {$ elementgetTag ()}> " ;
307295    }
308296
309-     private  function  resolveContentIsolated (string   $ _path ,  array   $ _data string 
297+     private  function  resolveContentIsolated (View   $ _view ,  string   $ _path string 
310298    {
311299        ob_start ();
312300
301+         $ _data$ _viewgetData ();
302+ 
313303        extract ($ _dataEXTR_SKIP );
314304
315305        include  $ _path
316306
307+         $ contentob_get_clean ();
308+ 
309+         // If the view defines local variables, we add them here to the view object as well 
310+         foreach  (get_defined_vars () as  $ key$ value
311+             if  (! $ _viewhas ($ key
312+                 $ _viewdata (...[$ key$ value
313+             }
314+         }
315+ 
316+         return  $ content
317+     }
318+ 
319+     private  function  evalContentIsolated (View $ _viewstring  $ _contentstring 
320+     {
321+         ob_start ();
322+ 
323+         $ _data$ _viewgetData ();
324+ 
325+         extract ($ _dataEXTR_SKIP );
326+ 
327+         try  {
328+             // TODO: find a better way of dealing with views that declare strict types 
329+             $ _contentstr_replace ('declare(strict_types=1); ' , '' , $ _content
330+ 
331+             /** @phpstan-ignore-next-line */ 
332+             eval ('?> '  . $ _content'<?php ' );
333+         } catch  (ParseError 
334+             return  $ _content
335+         }
336+ 
337+         // If the view defines local variables, we add them here to the view object as well 
338+         foreach  (get_defined_vars () as  $ key$ value
339+             if  (! $ _viewhas ($ key
340+                 $ _viewdata (...[$ key$ value
341+             }
342+         }
343+ 
317344        return  ob_get_clean ();
318345    }
319346}
0 commit comments