@@ -22,8 +22,7 @@ final class TempestViewRenderer implements ViewRenderer
2222 public function __construct (
2323 private readonly TempestViewCompiler $ compiler ,
2424 private readonly ViewCache $ viewCache ,
25- ) {
26- }
25+ ) {}
2726
2827 public function __get (string $ name ): mixed
2928 {
@@ -54,20 +53,21 @@ private function cleanupCompiled(string $compiled): string
5453
5554 // Cleanup and bundle imports
5655 $ imports = arr ();
57- $ compiled = $ compiled
58- ->replaceRegex ('/use .*;/ ' , function (array $ matches ) use (&$ imports ) {
59- $ imports [$ matches [0 ]] = $ matches [0 ];
60-
61- return '' ;
62- })
63- ->prepend (
64- sprintf (
65- '<?php
56+
57+ $ compiled = $ compiled ->replaceRegex ("/^\s*use (function )?.*;/m " , function (array $ matches ) use (&$ imports ) {
58+ $ imports [$ matches [0 ]] = $ matches [0 ];
59+
60+ return '' ;
61+ });
62+
63+ $ compiled = $ compiled ->prepend (
64+ sprintf (
65+ '<?php
6666%s
6767?> ' ,
68- $ imports ->implode (PHP_EOL ),
69- ),
70- );
68+ $ imports ->implode (PHP_EOL ),
69+ ),
70+ );
7171
7272 // Remove empty PHP blocks
7373 $ compiled = $ compiled ->replaceRegex ('/<\?php\s*\?>/ ' , '' );
@@ -100,9 +100,9 @@ private function renderCompiled(View $_view, string $_path): string
100100 public function escape (null |string |HtmlString |Stringable $ value ): string
101101 {
102102 if ($ value instanceof HtmlString) {
103- return (string ) $ value ;
103+ return (string )$ value ;
104104 }
105105
106- return htmlentities ((string ) $ value );
106+ return htmlentities ((string )$ value );
107107 }
108108}
0 commit comments