6666use ApiPlatform \JsonApi \Serializer \ItemNormalizer as JsonApiItemNormalizer ;
6767use ApiPlatform \JsonApi \Serializer \ObjectNormalizer as JsonApiObjectNormalizer ;
6868use ApiPlatform \JsonApi \Serializer \ReservedAttributeNameConverter ;
69- use ApiPlatform \JsonLd \Action \ContextAction ;
7069use ApiPlatform \JsonLd \AnonymousContextBuilderInterface ;
7170use ApiPlatform \JsonLd \ContextBuilder as JsonLdContextBuilder ;
7271use ApiPlatform \JsonLd \ContextBuilderInterface ;
124123use ApiPlatform \Laravel \State \SwaggerUiProcessor ;
125124use ApiPlatform \Laravel \State \SwaggerUiProvider ;
126125use ApiPlatform \Laravel \State \ValidateProvider ;
127- use ApiPlatform \Metadata \Exception \NotExposedHttpException ;
128126use ApiPlatform \Metadata \IdentifiersExtractor ;
129127use ApiPlatform \Metadata \IdentifiersExtractorInterface ;
130128use ApiPlatform \Metadata \InflectorInterface ;
196194use Illuminate \Config \Repository as ConfigRepository ;
197195use Illuminate \Contracts \Debug \ExceptionHandler as ExceptionHandlerInterface ;
198196use Illuminate \Contracts \Foundation \Application ;
199- use Illuminate \Contracts \Foundation \CachesRoutes ;
200- use Illuminate \Http \Request ;
201- use Illuminate \Routing \Route ;
202- use Illuminate \Routing \RouteCollection ;
203197use Illuminate \Routing \Router ;
204198use Illuminate \Support \ServiceProvider ;
205199use Negotiation \Negotiator ;
@@ -1346,7 +1340,7 @@ private function registerGraphQl(Application $app): void
13461340 /**
13471341 * Bootstrap services.
13481342 */
1349- public function boot (ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataCollectionFactoryInterface $ resourceMetadataFactory , Router $ router ): void
1343+ public function boot (): void
13501344 {
13511345 if ($ this ->app ->runningInConsole ()) {
13521346 $ this ->publishes ([
@@ -1368,94 +1362,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
13681362 $ typeBuilder ->setFieldsBuilderLocator (new ServiceLocator (['api_platform.graphql.fields_builder ' => $ fieldsBuilder ]));
13691363 }
13701364
1371- if (!$ this ->shouldRegisterRoutes ()) {
1372- return ;
1373- }
1374-
1375- $ globalMiddlewares = $ config ->get ('api-platform.routes.middleware ' );
1376- $ routeCollection = new RouteCollection ();
1377- foreach ($ resourceNameCollectionFactory ->create () as $ resourceClass ) {
1378- foreach ($ resourceMetadataFactory ->create ($ resourceClass ) as $ resourceMetadata ) {
1379- foreach ($ resourceMetadata ->getOperations () as $ operation ) {
1380- $ uriTemplate = $ operation ->getUriTemplate ();
1381- // _format is read by the middleware
1382- $ uriTemplate = $ operation ->getRoutePrefix ().str_replace ('{._format} ' , '{_format?} ' , $ uriTemplate );
1383- $ route = (new Route ([$ operation ->getMethod ()], $ uriTemplate , [ApiPlatformController::class, '__invoke ' ]))
1384- ->where ('_format ' , '^\.[a-zA-Z]+ ' )
1385- ->name ($ operation ->getName ())
1386- ->setDefaults (['_api_operation_name ' => $ operation ->getName (), '_api_resource_class ' => $ operation ->getClass ()]);
1387-
1388- $ route ->middleware (ApiPlatformMiddleware::class.': ' .$ operation ->getName ());
1389- $ route ->middleware ($ globalMiddlewares );
1390- $ route ->middleware ($ operation ->getMiddleware ());
1391-
1392- $ routeCollection ->add ($ route );
1393- }
1394- }
1395- }
1396-
1397- $ prefix = $ config ->get ('api-platform.defaults.route_prefix ' ) ?? '' ;
1398- $ route = new Route (['GET ' ], $ prefix .'/contexts/{shortName?}{_format?} ' , [ContextAction::class, '__invoke ' ]);
1399- $ route ->name ('api_jsonld_context ' );
1400- $ route ->middleware (ApiPlatformMiddleware::class);
1401- $ route ->middleware ($ globalMiddlewares );
1402- $ routeCollection ->add ($ route );
1403- $ route = new Route (['GET ' ], $ prefix .'/docs{_format?} ' , function (Request $ request , Application $ app ) {
1404- $ documentationAction = $ app ->make (DocumentationController::class);
1405-
1406- return $ documentationAction ->__invoke ($ request );
1407- });
1408- $ route ->name ('api_doc ' );
1409- $ route ->middleware (ApiPlatformMiddleware::class);
1410- $ route ->middleware ($ globalMiddlewares );
1411- $ routeCollection ->add ($ route );
1412-
1413- $ route = new Route (['GET ' ], $ prefix .'/.well-known/genid/{id} ' , function (): void {
1414- throw new NotExposedHttpException ('This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation. ' );
1415- });
1416- $ route ->name ('api_genid ' );
1417- $ route ->middleware (ApiPlatformMiddleware::class);
1418- $ route ->middleware ($ globalMiddlewares );
1419- $ routeCollection ->add ($ route );
1420-
1421- if ($ config ->get ('api-platform.graphql.enabled ' )) {
1422- $ route = new Route (['POST ' , 'GET ' ], $ prefix .'/graphql ' , function (Application $ app , Request $ request ) {
1423- $ entrypointAction = $ app ->make (GraphQlEntrypointController::class);
1424-
1425- return $ entrypointAction ->__invoke ($ request );
1426- });
1427- $ route ->middleware ($ globalMiddlewares );
1428- $ routeCollection ->add ($ route );
1429-
1430- $ route = new Route (['GET ' ], $ prefix .'/graphiql ' , function (Application $ app ) {
1431- $ controller = $ app ->make (GraphiQlController::class);
1432-
1433- return $ controller ->__invoke ();
1434- });
1435- $ route ->middleware ($ globalMiddlewares );
1436- $ routeCollection ->add ($ route );
1437- }
1438-
1439- $ route = new Route (['GET ' ], $ prefix .'/{index?}{_format?} ' , function (Request $ request , Application $ app ) {
1440- $ entrypointAction = $ app ->make (EntrypointController::class);
1441-
1442- return $ entrypointAction ->__invoke ($ request );
1443- });
1444- $ route ->where ('index ' , 'index ' );
1445- $ route ->name ('api_entrypoint ' );
1446- $ route ->middleware (ApiPlatformMiddleware::class);
1447- $ route ->middleware ($ globalMiddlewares );
1448- $ routeCollection ->add ($ route );
1449-
1450- $ router ->setRoutes ($ routeCollection );
1451- }
1452-
1453- private function shouldRegisterRoutes (): bool
1454- {
1455- if ($ this ->app instanceof CachesRoutes && $ this ->app ->routesAreCached ()) {
1456- return false ;
1457- }
1458-
1459- return true ;
1365+ $ this ->loadRoutesFrom (__DIR__ .'/routes/api.php ' );
14601366 }
14611367}
0 commit comments