55
66use Symfony \Component \HttpFoundation \Request ;
77use Symfony \Component \HttpFoundation \Response ;
8+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
9+ use Symfony \Component \HttpKernel \Profiler \Profiler ;
810use Twig \Environment ;
911use Qossmic \TwigDocBundle \Component \ComponentItem ;
1012use Qossmic \TwigDocBundle \Service \ComponentService ;
@@ -13,7 +15,8 @@ class TwigDocController
1315{
1416 public function __construct (
1517 private readonly Environment $ twig ,
16- private readonly ComponentService $ componentService
18+ private readonly ComponentService $ componentService ,
19+ private readonly ?Profiler $ profiler = null
1720 )
1821 {
1922 }
@@ -28,7 +31,7 @@ public function index(Request $request): Response
2831 }
2932
3033 return new Response (
31- $ this ->twig ->render ('@TwigDoc/pages/index .html.twig ' , [
34+ $ this ->twig ->render ('@TwigDoc/documentation .html.twig ' , [
3235 'components ' => $ components ,
3336 'filterQuery ' => $ filterQuery ,
3437 'filterType ' => $ filterType ?? null ,
@@ -42,4 +45,25 @@ public function invalidComponents(): Response
4245 $ this ->twig ->render ('@TwigDoc/pages/invalid_components.html.twig ' )
4346 );
4447 }
48+
49+ public function componentView (Request $ request ): Response
50+ {
51+ $ name = $ request ->query ->get ('name ' );
52+ $ component = $ this ->componentService ->getComponent ($ name );
53+ if (!$ component ) {
54+ throw new NotFoundHttpException (sprintf ('Component %s is unknown ' , $ name ));
55+ }
56+ $ breakpoint = $ request ->query ->get ('breakpoint ' );
57+ // disable profiler to get rid of toolbar in dev
58+ if ($ this ->profiler ) {
59+ $ this ->profiler ->disable ();
60+ }
61+ return new Response (
62+ $ this ->twig ->render ('@TwigDoc/component.html.twig ' , [
63+ 'component ' => $ component ,
64+ 'componentData ' => $ request ->query ->all ('data ' ),
65+ 'quantity ' => $ request ->query ->get ('quantity ' )
66+ ])
67+ );
68+ }
4569}
0 commit comments