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 ;
78
77
use ApiPlatform \JsonSchema \SchemaFactory ;
79
78
use ApiPlatform \JsonSchema \SchemaFactoryInterface ;
80
79
use ApiPlatform \Laravel \ApiResource \Error ;
80
+ use ApiPlatform \Laravel \ApiResource \ValidationError ;
81
81
use ApiPlatform \Laravel \Controller \ApiPlatformController ;
82
82
use ApiPlatform \Laravel \Controller \DocumentationController ;
83
83
use ApiPlatform \Laravel \Controller \EntrypointController ;
125
125
use ApiPlatform \Laravel \State \SwaggerUiProcessor ;
126
126
use ApiPlatform \Laravel \State \SwaggerUiProvider ;
127
127
use ApiPlatform \Laravel \State \ValidateProvider ;
128
- use ApiPlatform \Metadata \Exception \NotExposedHttpException ;
129
128
use ApiPlatform \Metadata \IdentifiersExtractor ;
130
129
use ApiPlatform \Metadata \IdentifiersExtractorInterface ;
131
130
use ApiPlatform \Metadata \InflectorInterface ;
179
178
use ApiPlatform \Serializer \SerializerContextBuilder ;
180
179
use ApiPlatform \State \CallableProcessor ;
181
180
use ApiPlatform \State \CallableProvider ;
181
+ use ApiPlatform \State \ErrorProvider ;
182
182
use ApiPlatform \State \Pagination \Pagination ;
183
183
use ApiPlatform \State \Pagination \PaginationOptions ;
184
184
use ApiPlatform \State \ParameterProviderInterface ;
197
197
use Illuminate \Config \Repository as ConfigRepository ;
198
198
use Illuminate \Contracts \Debug \ExceptionHandler as ExceptionHandlerInterface ;
199
199
use 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 ;
204
200
use Illuminate \Routing \Router ;
205
201
use Illuminate \Support \ServiceProvider ;
206
202
use Negotiation \Negotiator ;
@@ -254,6 +250,7 @@ public function register(): void
254
250
);
255
251
});
256
252
253
+ $ this ->app ->singleton (ModelMetadata::class);
257
254
$ this ->app ->bind (LoaderInterface::class, AttributeLoader::class);
258
255
$ this ->app ->bind (ClassMetadataFactoryInterface::class, ClassMetadataFactory::class);
259
256
$ this ->app ->singleton (ClassMetadataFactory::class, function (Application $ app ) {
@@ -323,7 +320,7 @@ public function register(): void
323
320
$ app ->make (ResourceClassResolverInterface::class)
324
321
),
325
322
),
326
- true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('cache.default ' , 'file ' )
323
+ true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('api-platform.cache ' , 'file ' )
327
324
);
328
325
});
329
326
@@ -341,7 +338,7 @@ public function register(): void
341
338
)
342
339
)
343
340
),
344
- true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('cache.default ' , 'file ' )
341
+ true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('api-platform.cache ' , 'file ' )
345
342
);
346
343
});
347
344
@@ -412,7 +409,7 @@ public function register(): void
412
409
$ app ->make ('filters ' )
413
410
)
414
411
),
415
- true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('cache.default ' , 'file ' )
412
+ true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('api-platform.cache ' , 'file ' )
416
413
);
417
414
});
418
415
@@ -779,6 +776,9 @@ public function register(): void
779
776
licenseUrl: $ config ->get ('api-platform.swagger_ui.license.url ' , '' ),
780
777
persistAuthorization: $ config ->get ('api-platform.swagger_ui.persist_authorization ' , false ),
781
778
httpAuth: $ config ->get ('api-platform.swagger_ui.http_auth ' , []),
779
+ tags: $ config ->get ('api-platform.openapi.tags ' , []),
780
+ errorResourceClass: Error::class,
781
+ validationErrorResourceClass: ValidationError::class
782
782
);
783
783
});
784
784
@@ -852,7 +852,9 @@ public function register(): void
852
852
null ,
853
853
$ config ->get ('api-platform.formats ' ),
854
854
$ app ->make (Options::class),
855
- $ app ->make (PaginationOptions::class), // ?PaginationOptions $paginationOptions = null,
855
+ $ app ->make (PaginationOptions::class),
856
+ null ,
857
+ $ config ->get ('api-platform.error_formats ' ),
856
858
// ?RouterInterface $router = null
857
859
);
858
860
});
@@ -1222,6 +1224,18 @@ private function registerGraphQl(Application $app): void
1222
1224
});
1223
1225
$ app ->alias (GraphQlReadProvider::class, 'api_platform.graphql.state_provider.read ' );
1224
1226
1227
+ $ app ->singleton (ErrorProvider::class, function (Application $ app ) {
1228
+ /** @var ConfigRepository */
1229
+ $ config = $ app ['config ' ];
1230
+
1231
+ return new ErrorProvider (
1232
+ $ config ->get ('app.debug ' ),
1233
+ $ app ->make (ResourceClassResolver::class),
1234
+ $ app ->make (ResourceMetadataCollectionFactoryInterface::class),
1235
+ );
1236
+ });
1237
+ $ app ->tag ([ErrorProvider::class], ProviderInterface::class);
1238
+
1225
1239
$ app ->singleton (ResolverProvider::class, function (Application $ app ) {
1226
1240
$ resolvers = iterator_to_array ($ app ->tagged ('api_platform.graphql.resolver ' ));
1227
1241
$ taggedItemResolvers = iterator_to_array ($ app ->tagged (QueryItemResolverInterface::class));
@@ -1320,7 +1334,7 @@ private function registerGraphQl(Application $app): void
1320
1334
/** @var ConfigRepository */
1321
1335
$ config = $ app ['config ' ];
1322
1336
1323
- return new Executor ($ config ->get ('api-platform.graphql.introspection.enabled ' ) ?? false , $ config ->get ('api-platform.graphql.max_query_complexity ' ), $ config ->get ('api-platform.graphql.max_query_depth ' ));
1337
+ return new Executor ($ config ->get ('api-platform.graphql.introspection.enabled ' ) ?? false , $ config ->get ('api-platform.graphql.max_query_complexity ' ) ?? 500 , $ config ->get ('api-platform.graphql.max_query_depth ' ) ?? 200 );
1324
1338
});
1325
1339
1326
1340
$ app ->singleton (GraphiQlController::class, function (Application $ app ) {
@@ -1351,7 +1365,7 @@ private function registerGraphQl(Application $app): void
1351
1365
/**
1352
1366
* Bootstrap services.
1353
1367
*/
1354
- public function boot (ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataCollectionFactoryInterface $ resourceMetadataFactory , Router $ router ): void
1368
+ public function boot (): void
1355
1369
{
1356
1370
if ($ this ->app ->runningInConsole ()) {
1357
1371
$ this ->publishes ([
@@ -1373,94 +1387,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
1373
1387
$ typeBuilder ->setFieldsBuilderLocator (new ServiceLocator (['api_platform.graphql.fields_builder ' => $ fieldsBuilder ]));
1374
1388
}
1375
1389
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 ;
1390
+ $ this ->loadRoutesFrom (__DIR__ .'/routes/api.php ' );
1465
1391
}
1466
1392
}
0 commit comments