44
44
use ApiPlatform \GraphQl \Type \TypesFactory ;
45
45
use ApiPlatform \GraphQl \Type \TypesFactoryInterface ;
46
46
use ApiPlatform \Hydra \JsonSchema \SchemaFactory as HydraSchemaFactory ;
47
- use ApiPlatform \Hydra \Serializer \CollectionFiltersNormalizer as HydraFiltersCollectionNormalizer ;
47
+ use ApiPlatform \Hydra \Serializer \CollectionFiltersNormalizer as HydraCollectionFiltersNormalizer ;
48
48
use ApiPlatform \Hydra \Serializer \CollectionNormalizer as HydraCollectionNormalizer ;
49
49
use ApiPlatform \Hydra \Serializer \DocumentationNormalizer as HydraDocumentationNormalizer ;
50
50
use ApiPlatform \Hydra \Serializer \EntrypointNormalizer as HydraEntrypointNormalizer ;
51
+ use ApiPlatform \Hydra \Serializer \HydraPrefixNameConverter ;
51
52
use ApiPlatform \Hydra \Serializer \PartialCollectionViewNormalizer as HydraPartialCollectionViewNormalizer ;
52
53
use ApiPlatform \Hydra \State \HydraLinkProcessor ;
53
54
use ApiPlatform \JsonApi \JsonSchema \SchemaFactory as JsonApiSchemaFactory ;
@@ -219,7 +220,6 @@ class ApiPlatformProvider extends ServiceProvider
219
220
public function register (): void
220
221
{
221
222
$ this ->mergeConfigFrom (__DIR__ .'/config/api-platform.php ' , 'api-platform ' );
222
- $ defaultContext = [];
223
223
224
224
$ this ->app ->singleton (PropertyInfoExtractorInterface::class, function () {
225
225
$ phpDocExtractor = class_exists (DocBlockFactory::class) ? new PhpDocExtractor () : null ;
@@ -384,7 +384,10 @@ public function register(): void
384
384
});
385
385
386
386
$ this ->app ->bind (NameConverterInterface::class, function (Application $ app ) {
387
- return new MetadataAwareNameConverter ($ app ->make (ClassMetadataFactoryInterface::class), $ app ->make (SnakeCaseToCamelCaseNameConverter::class));
387
+ $ config = $ app ['config ' ];
388
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
389
+
390
+ return new HydraPrefixNameConverter (new MetadataAwareNameConverter ($ app ->make (ClassMetadataFactoryInterface::class), $ app ->make (SnakeCaseToCamelCaseNameConverter::class)), $ defaultContext );
388
391
});
389
392
390
393
$ this ->app ->bind (OperationMetadataFactoryInterface::class, OperationMetadataFactory::class);
@@ -528,20 +531,29 @@ public function register(): void
528
531
529
532
$ this ->app ->bind (ProcessorInterface::class, HydraLinkProcessor::class);
530
533
531
- $ this ->app ->singleton (ObjectNormalizer::class, function () {
532
- return new ObjectNormalizer ();
534
+ $ this ->app ->singleton (ObjectNormalizer::class, function (Application $ app ) {
535
+ $ config = $ app ['config ' ];
536
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
537
+
538
+ return new ObjectNormalizer (defaultContext: $ defaultContext );
533
539
});
534
540
535
- $ this ->app ->singleton (DateTimeNormalizer::class, function () {
536
- return new DateTimeNormalizer ();
541
+ $ this ->app ->singleton (DateTimeNormalizer::class, function (Application $ app ) {
542
+ $ config = $ app ['config ' ];
543
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
544
+
545
+ return new DateTimeNormalizer (defaultContext: $ defaultContext );
537
546
});
538
547
539
548
$ this ->app ->singleton (DateTimeZoneNormalizer::class, function () {
540
549
return new DateTimeZoneNormalizer ();
541
550
});
542
551
543
- $ this ->app ->singleton (DateIntervalNormalizer::class, function () {
544
- return new DateIntervalNormalizer ();
552
+ $ this ->app ->singleton (DateIntervalNormalizer::class, function (Application $ app ) {
553
+ $ config = $ app ['config ' ];
554
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
555
+
556
+ return new DateIntervalNormalizer (defaultContext: $ defaultContext );
545
557
});
546
558
547
559
$ this ->app ->singleton (JsonEncoder::class, function () {
@@ -589,14 +601,18 @@ public function register(): void
589
601
590
602
$ this ->app ->bind (ContextBuilderInterface::class, JsonLdContextBuilder::class);
591
603
$ this ->app ->singleton (JsonLdContextBuilder::class, function (Application $ app ) {
604
+ $ config = $ app ['config ' ];
605
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
606
+
592
607
return new JsonLdContextBuilder (
593
608
$ app ->make (ResourceNameCollectionFactoryInterface::class),
594
609
$ app ->make (ResourceMetadataCollectionFactoryInterface::class),
595
610
$ app ->make (PropertyNameCollectionFactoryInterface::class),
596
611
$ app ->make (PropertyMetadataFactoryInterface::class),
597
612
$ app ->make (UrlGeneratorInterface::class),
598
613
$ app ->make (IriConverterInterface::class),
599
- $ app ->make (NameConverterInterface::class)
614
+ $ app ->make (NameConverterInterface::class),
615
+ $ defaultContext
600
616
);
601
617
});
602
618
@@ -608,7 +624,11 @@ public function register(): void
608
624
return new ResourceAccessChecker ();
609
625
});
610
626
611
- $ this ->app ->singleton (ItemNormalizer::class, function (Application $ app ) use ($ defaultContext ) {
627
+ $ this ->app ->singleton (ItemNormalizer::class, function (Application $ app ) {
628
+ /** @var ConfigRepository */
629
+ $ config = $ app ['config ' ];
630
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
631
+
612
632
return new ItemNormalizer (
613
633
$ app ->make (PropertyNameCollectionFactoryInterface::class),
614
634
$ app ->make (PropertyMetadataFactoryInterface::class),
@@ -733,8 +753,12 @@ public function register(): void
733
753
);
734
754
});
735
755
$ this ->app ->singleton (HydraSchemaFactory::class, function (Application $ app ) {
756
+ $ config = $ app ['config ' ];
757
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
758
+
736
759
return new HydraSchemaFactory (
737
760
$ app ->make (JsonApiSchemaFactory::class),
761
+ $ defaultContext
738
762
);
739
763
});
740
764
@@ -745,19 +769,26 @@ public function register(): void
745
769
});
746
770
747
771
$ this ->app ->singleton (HydraDocumentationNormalizer::class, function (Application $ app ) {
772
+ $ config = $ app ['config ' ];
773
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
774
+
748
775
return new HydraDocumentationNormalizer (
749
776
$ app ->make (ResourceMetadataCollectionFactoryInterface::class),
750
777
$ app ->make (PropertyNameCollectionFactoryInterface::class),
751
778
$ app ->make (PropertyMetadataFactoryInterface::class),
752
779
$ app ->make (ResourceClassResolverInterface::class),
753
780
$ app ->make (UrlGeneratorInterface::class),
754
- $ app ->make (NameConverterInterface::class)
781
+ $ app ->make (NameConverterInterface::class),
782
+ $ defaultContext
755
783
);
756
784
});
757
785
758
- $ this ->app ->singleton (HydraPartialCollectionViewNormalizer::class, function (Application $ app ) use ($ defaultContext ) {
786
+ $ this ->app ->singleton (HydraPartialCollectionViewNormalizer::class, function (Application $ app ) {
787
+ $ config = $ app ['config ' ];
788
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
789
+
759
790
return new HydraPartialCollectionViewNormalizer (
760
- new HydraFiltersCollectionNormalizer (
791
+ new HydraCollectionFiltersNormalizer (
761
792
new HydraCollectionNormalizer (
762
793
$ app ->make (ContextBuilderInterface::class),
763
794
$ app ->make (ResourceClassResolverInterface::class),
@@ -767,11 +798,15 @@ public function register(): void
767
798
),
768
799
$ app ->make (ResourceMetadataCollectionFactoryInterface::class),
769
800
$ app ->make (ResourceClassResolverInterface::class),
801
+ null , // filterLocator, we use only Parameters with Laravel and we don't need to call filters there
802
+ $ defaultContext
770
803
),
771
804
'page ' ,
772
805
'pagination ' ,
773
806
$ app ->make (ResourceMetadataCollectionFactoryInterface::class),
774
807
$ app ->make (PropertyAccessorInterface::class),
808
+ $ config ->get ('api-platform.url_generation_strategy ' , UrlGeneratorInterface::ABS_PATH ),
809
+ $ defaultContext ,
775
810
);
776
811
});
777
812
@@ -798,7 +833,10 @@ public function register(): void
798
833
);
799
834
});
800
835
801
- $ this ->app ->singleton (JsonApiItemNormalizer::class, function (Application $ app ) use ($ defaultContext ) {
836
+ $ this ->app ->singleton (JsonApiItemNormalizer::class, function (Application $ app ) {
837
+ $ config = $ app ['config ' ];
838
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
839
+
802
840
return new JsonApiItemNormalizer (
803
841
$ app ->make (PropertyNameCollectionFactoryInterface::class),
804
842
$ app ->make (PropertyMetadataFactoryInterface::class),
@@ -915,7 +953,10 @@ public function register(): void
915
953
return new Serializer (iterator_to_array ($ list ), [new JsonEncoder ('json ' ), $ app ->make (JsonEncoder::class), new JsonEncoder ('jsonopenapi ' ), new JsonEncoder ('jsonapi ' )]);
916
954
});
917
955
918
- $ this ->app ->singleton (JsonLdItemNormalizer::class, function (Application $ app ) use ($ defaultContext ) {
956
+ $ this ->app ->singleton (JsonLdItemNormalizer::class, function (Application $ app ) {
957
+ $ config = $ app ['config ' ];
958
+ $ defaultContext = $ config ->get ('api-platform.serializer ' , []);
959
+
919
960
return new JsonLdItemNormalizer (
920
961
$ app ->make (ResourceMetadataCollectionFactoryInterface::class),
921
962
$ app ->make (PropertyNameCollectionFactoryInterface::class),
0 commit comments