1616use ApiPlatform \Documentation \Entrypoint ;
1717use ApiPlatform \Metadata \Get ;
1818use ApiPlatform \Metadata \Resource \Factory \ResourceNameCollectionFactoryInterface ;
19+ use ApiPlatform \Metadata \Resource \ResourceNameCollection ;
1920use ApiPlatform \State \ProcessorInterface ;
2021use ApiPlatform \State \ProviderInterface ;
2122use Symfony \Component \HttpFoundation \Request ;
2728 */
2829final class EntrypointAction
2930{
31+ private static ResourceNameCollection $ resourceNameCollection ;
32+
3033 public function __construct (
3134 private readonly ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory ,
3235 private readonly ProviderInterface $ provider ,
@@ -35,12 +38,21 @@ public function __construct(
3538 ) {
3639 }
3740
38- public function __invoke (Request $ request = null )
41+ public function __invoke (Request $ request )
3942 {
43+ static ::$ resourceNameCollection = $ this ->resourceNameCollectionFactory ->create ();
4044 $ context = ['request ' => $ request ];
41- $ operation = new Get (outputFormats: $ this ->documentationFormats , read: true , serialize: true , class: Entrypoint::class, provider: fn () => new Entrypoint ($ this ->resourceNameCollectionFactory ->create ()));
45+ $ request ->attributes ->set ('_api_platform_disable_listeners ' , true );
46+ $ operation = new Get (outputFormats: $ this ->documentationFormats , read: true , serialize: true , class: Entrypoint::class, provider: [self ::class, 'provide ' ]);
47+ $ request ->attributes ->set ('_api_operation ' , $ operation );
4248 $ body = $ this ->provider ->provide ($ operation , [], $ context );
49+ $ operation = $ request ->attributes ->get ('_api_operation ' );
4350
4451 return $ this ->processor ->process ($ body , $ operation , [], $ context );
4552 }
53+
54+ public static function provide (): Entrypoint
55+ {
56+ return new Entrypoint (static ::$ resourceNameCollection );
57+ }
4658}
0 commit comments