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 ;
125124use ApiPlatform \Laravel \State \SwaggerUiProcessor ;
126125use ApiPlatform \Laravel \State \SwaggerUiProvider ;
127126use ApiPlatform \Laravel \State \ValidateProvider ;
128- use ApiPlatform \Metadata \Exception \NotExposedHttpException ;
129127use ApiPlatform \Metadata \IdentifiersExtractor ;
130128use ApiPlatform \Metadata \IdentifiersExtractorInterface ;
131129use ApiPlatform \Metadata \InflectorInterface ;
197195use Illuminate \Config \Repository as ConfigRepository ;
198196use Illuminate \Contracts \Debug \ExceptionHandler as ExceptionHandlerInterface ;
199197use Illuminate \Contracts \Foundation \Application ;
200- use Illuminate \Contracts \Foundation \CachesRoutes ;
201- use Illuminate \Http \Request ;
202- use Illuminate \Routing \Route ;
203- use Illuminate \Routing \RouteCollection ;
204198use Illuminate \Routing \Router ;
205199use Illuminate \Support \ServiceProvider ;
206200use Negotiation \Negotiator ;
@@ -1351,7 +1345,7 @@ private function registerGraphQl(Application $app): void
13511345 /**
13521346 * Bootstrap services.
13531347 */
1354- public function boot (ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataCollectionFactoryInterface $ resourceMetadataFactory , Router $ router ): void
1348+ public function boot (): void
13551349 {
13561350 if ($ this ->app ->runningInConsole ()) {
13571351 $ this ->publishes ([
@@ -1373,94 +1367,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
13731367 $ typeBuilder ->setFieldsBuilderLocator (new ServiceLocator (['api_platform.graphql.fields_builder ' => $ fieldsBuilder ]));
13741368 }
13751369
1376- if (!$ this ->shouldRegisterRoutes ()) {
1377- return ;
1378- }
1379-
1380- $ globalMiddlewares = $ config ->get ('api-platform.routes.middleware ' );
1381- $ routeCollection = new RouteCollection ();
1382- foreach ($ resourceNameCollectionFactory ->create () as $ resourceClass ) {
1383- foreach ($ resourceMetadataFactory ->create ($ resourceClass ) as $ resourceMetadata ) {
1384- foreach ($ resourceMetadata ->getOperations () as $ operation ) {
1385- $ uriTemplate = $ operation ->getUriTemplate ();
1386- // _format is read by the middleware
1387- $ uriTemplate = $ operation ->getRoutePrefix ().str_replace ('{._format} ' , '{_format?} ' , $ uriTemplate );
1388- $ route = (new Route ([$ operation ->getMethod ()], $ uriTemplate , [ApiPlatformController::class, '__invoke ' ]))
1389- ->where ('_format ' , '^\.[a-zA-Z]+ ' )
1390- ->name ($ operation ->getName ())
1391- ->setDefaults (['_api_operation_name ' => $ operation ->getName (), '_api_resource_class ' => $ operation ->getClass ()]);
1392-
1393- $ route ->middleware (ApiPlatformMiddleware::class.': ' .$ operation ->getName ());
1394- $ route ->middleware ($ globalMiddlewares );
1395- $ route ->middleware ($ operation ->getMiddleware ());
1396-
1397- $ routeCollection ->add ($ route );
1398- }
1399- }
1400- }
1401-
1402- $ prefix = $ config ->get ('api-platform.defaults.route_prefix ' ) ?? '' ;
1403- $ route = new Route (['GET ' ], $ prefix .'/contexts/{shortName?}{_format?} ' , [ContextAction::class, '__invoke ' ]);
1404- $ route ->name ('api_jsonld_context ' );
1405- $ route ->middleware (ApiPlatformMiddleware::class);
1406- $ route ->middleware ($ globalMiddlewares );
1407- $ routeCollection ->add ($ route );
1408- $ route = new Route (['GET ' ], $ prefix .'/docs{_format?} ' , function (Request $ request , Application $ app ) {
1409- $ documentationAction = $ app ->make (DocumentationController::class);
1410-
1411- return $ documentationAction ->__invoke ($ request );
1412- });
1413- $ route ->name ('api_doc ' );
1414- $ route ->middleware (ApiPlatformMiddleware::class);
1415- $ route ->middleware ($ globalMiddlewares );
1416- $ routeCollection ->add ($ route );
1417-
1418- $ route = new Route (['GET ' ], $ prefix .'/.well-known/genid/{id} ' , function (): void {
1419- throw new NotExposedHttpException ('This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation. ' );
1420- });
1421- $ route ->name ('api_genid ' );
1422- $ route ->middleware (ApiPlatformMiddleware::class);
1423- $ route ->middleware ($ globalMiddlewares );
1424- $ routeCollection ->add ($ route );
1425-
1426- if ($ config ->get ('api-platform.graphql.enabled ' )) {
1427- $ route = new Route (['POST ' , 'GET ' ], $ prefix .'/graphql ' , function (Application $ app , Request $ request ) {
1428- $ entrypointAction = $ app ->make (GraphQlEntrypointController::class);
1429-
1430- return $ entrypointAction ->__invoke ($ request );
1431- });
1432- $ route ->middleware ($ globalMiddlewares );
1433- $ routeCollection ->add ($ route );
1434-
1435- $ route = new Route (['GET ' ], $ prefix .'/graphiql ' , function (Application $ app ) {
1436- $ controller = $ app ->make (GraphiQlController::class);
1437-
1438- return $ controller ->__invoke ();
1439- });
1440- $ route ->middleware ($ globalMiddlewares );
1441- $ routeCollection ->add ($ route );
1442- }
1443-
1444- $ route = new Route (['GET ' ], $ prefix .'/{index?}{_format?} ' , function (Request $ request , Application $ app ) {
1445- $ entrypointAction = $ app ->make (EntrypointController::class);
1446-
1447- return $ entrypointAction ->__invoke ($ request );
1448- });
1449- $ route ->where ('index ' , 'index ' );
1450- $ route ->name ('api_entrypoint ' );
1451- $ route ->middleware (ApiPlatformMiddleware::class);
1452- $ route ->middleware ($ globalMiddlewares );
1453- $ routeCollection ->add ($ route );
1454-
1455- $ router ->setRoutes ($ routeCollection );
1456- }
1457-
1458- private function shouldRegisterRoutes (): bool
1459- {
1460- if ($ this ->app instanceof CachesRoutes && $ this ->app ->routesAreCached ()) {
1461- return false ;
1462- }
1463-
1464- return true ;
1370+ $ this ->loadRoutesFrom (__DIR__ .'/routes/api.php ' );
14651371 }
14661372}
0 commit comments