@@ -33,18 +33,12 @@ public function __invoke(Request $request): Response
3333 $ outputValue = ob_get_clean ();
3434
3535 if ($ returnValue === 1 && is_string ($ outputValue )) {
36- if (html_contains_full_html ($ outputValue )) {
37- return new Response ($ outputValue , 200 );
38- } else {
39- $ layout = html_extract_layout ($ outputValue );
40- $ title = html_extract_title ($ outputValue , basename ($ path ));
41- return $ this ->html ($ layout , ['title ' => $ title , 'html ' => $ outputValue ]);
42- }
36+ return $ this ->handleHtml ($ outputValue , basename ($ path ));
4337 } elseif (is_string ($ returnValue )) {
4438 if (is_string ($ outputValue ) && strlen ($ outputValue ) > 0 ) {
4539 throw new \Exception ('In the PHP file the return value must be omitted if an output was made via echo: ' . $ path );
4640 }
47- return new Response ($ returnValue , 200 );
41+ return $ this -> handleHtml ($ returnValue , basename ( $ path ) );
4842 } elseif (is_array ($ returnValue )) {
4943 return $ this ->json ($ returnValue );
5044 } elseif ($ returnValue instanceof Response) {
@@ -54,6 +48,17 @@ public function __invoke(Request $request): Response
5448 }
5549 }
5650
51+ private function handleHtml (string $ content , string $ defaultTitle ): Response
52+ {
53+ if (html_contains_full_html ($ content )) {
54+ return new Response ($ content , 200 );
55+ } else {
56+ $ layout = html_extract_layout ($ content );
57+ $ title = html_extract_title ($ content , $ defaultTitle );
58+ return $ this ->html ($ layout , ['title ' => $ title , 'html ' => $ content ]);
59+ }
60+ }
61+
5762 public function html (string $ template , array $ context = []): Response
5863 {
5964 $ html = $ this ->render ($ template , $ context );
0 commit comments