77use Symfony \Component \HttpFoundation \Request ;
88use Symfony \Component \HttpFoundation \Response ;
99
10+ use function tebe \zack \html_contains_full_html ;
11+ use function tebe \zack \html_extract_layout ;
1012use function tebe \zack \html_extract_title ;
1113
1214class PhpRouteHandler
@@ -31,8 +33,13 @@ public function __invoke(Request $request): Response
3133 $ outputValue = ob_get_clean ();
3234
3335 if ($ returnValue === 1 && is_string ($ outputValue )) {
34- $ title = html_extract_title ($ outputValue , basename ($ path ));
35- return $ this ->html ('route-handler.html.twig ' , ['title ' => $ title , 'html ' => $ 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+ }
3643 } elseif (is_string ($ returnValue )) {
3744 if (is_string ($ outputValue ) && strlen ($ outputValue ) > 0 ) {
3845 throw new \Exception ('In the PHP file the return value must be omitted if an output was made via echo: ' . $ path );
@@ -68,6 +75,7 @@ public function redirect(string $url, int $status = 302): Response
6875
6976 public function render (string $ template , array $ context = []): string
7077 {
78+ /** @var \Twig\Environment $twig */
7179 $ twig = $ this ->container ->get ('twig ' );
7280 return $ twig ->render ($ template , $ context );
7381 }
0 commit comments