66
66
use ApiPlatform \JsonApi \Serializer \ItemNormalizer as JsonApiItemNormalizer ;
67
67
use ApiPlatform \JsonApi \Serializer \ObjectNormalizer as JsonApiObjectNormalizer ;
68
68
use ApiPlatform \JsonApi \Serializer \ReservedAttributeNameConverter ;
69
- use ApiPlatform \JsonLd \Action \ContextAction ;
70
69
use ApiPlatform \JsonLd \AnonymousContextBuilderInterface ;
71
70
use ApiPlatform \JsonLd \ContextBuilder as JsonLdContextBuilder ;
72
71
use ApiPlatform \JsonLd \ContextBuilderInterface ;
124
123
use ApiPlatform \Laravel \State \SwaggerUiProcessor ;
125
124
use ApiPlatform \Laravel \State \SwaggerUiProvider ;
126
125
use ApiPlatform \Laravel \State \ValidateProvider ;
127
- use ApiPlatform \Metadata \Exception \NotExposedHttpException ;
128
126
use ApiPlatform \Metadata \IdentifiersExtractor ;
129
127
use ApiPlatform \Metadata \IdentifiersExtractorInterface ;
130
128
use ApiPlatform \Metadata \InflectorInterface ;
196
194
use Illuminate \Config \Repository as ConfigRepository ;
197
195
use Illuminate \Contracts \Debug \ExceptionHandler as ExceptionHandlerInterface ;
198
196
use 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 ;
203
197
use Illuminate \Routing \Router ;
204
198
use Illuminate \Support \ServiceProvider ;
205
199
use Negotiation \Negotiator ;
@@ -1346,7 +1340,7 @@ private function registerGraphQl(Application $app): void
1346
1340
/**
1347
1341
* Bootstrap services.
1348
1342
*/
1349
- public function boot (ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataCollectionFactoryInterface $ resourceMetadataFactory , Router $ router ): void
1343
+ public function boot (): void
1350
1344
{
1351
1345
if ($ this ->app ->runningInConsole ()) {
1352
1346
$ this ->publishes ([
@@ -1368,94 +1362,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
1368
1362
$ typeBuilder ->setFieldsBuilderLocator (new ServiceLocator (['api_platform.graphql.fields_builder ' => $ fieldsBuilder ]));
1369
1363
}
1370
1364
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 ' );
1460
1366
}
1461
1367
}
0 commit comments