16
16
use ApiPlatform \Api \IriConverterInterface ;
17
17
use ApiPlatform \Api \ResourceClassResolverInterface ;
18
18
use ApiPlatform \Api \UrlGeneratorInterface ;
19
- use ApiPlatform \Core \Api \IriConverterInterface as LegacyIriConverterInterface ;
20
- use ApiPlatform \Core \Api \OperationType ;
21
19
use ApiPlatform \JsonLd \ContextBuilderInterface ;
22
20
use ApiPlatform \JsonLd \Serializer \JsonLdContextTrait ;
23
21
use ApiPlatform \Serializer \ContextTrait ;
@@ -50,14 +48,10 @@ final class CollectionNormalizer implements NormalizerInterface, NormalizerAware
50
48
self ::IRI_ONLY => false ,
51
49
];
52
50
53
- public function __construct (ContextBuilderInterface $ contextBuilder , ResourceClassResolverInterface $ resourceClassResolver , $ iriConverter , array $ defaultContext = [])
51
+ public function __construct (ContextBuilderInterface $ contextBuilder , ResourceClassResolverInterface $ resourceClassResolver , IriConverterInterface $ iriConverter , array $ defaultContext = [])
54
52
{
55
53
$ this ->contextBuilder = $ contextBuilder ;
56
54
$ this ->resourceClassResolver = $ resourceClassResolver ;
57
-
58
- if ($ iriConverter instanceof LegacyIriConverterInterface) {
59
- trigger_deprecation ('api-platform/core ' , '2.7 ' , sprintf ('Use an implementation of "%s" instead of "%s". ' , IriConverterInterface::class, LegacyIriConverterInterface::class));
60
- }
61
55
$ this ->iriConverter = $ iriConverter ;
62
56
$ this ->defaultContext = array_merge ($ this ->defaultContext , $ defaultContext );
63
57
}
@@ -84,22 +78,15 @@ public function normalize($object, $format = null, array $context = []): array
84
78
$ resourceClass = $ this ->resourceClassResolver ->getResourceClass ($ object , $ context ['resource_class ' ]);
85
79
$ context = $ this ->initContext ($ resourceClass , $ context );
86
80
$ data = $ this ->addJsonLdContext ($ this ->contextBuilder , $ resourceClass , $ context );
87
-
88
- if ($ this ->iriConverter instanceof LegacyIriConverterInterface) {
89
- // TODO: remove in 3.0
90
- $ data ['@id ' ] = isset ($ context ['operation_type ' ]) && OperationType::SUBRESOURCE === $ context ['operation_type ' ] ? $ this ->iriConverter ->getSubresourceIriFromResourceClass ($ resourceClass , $ context ) : $ this ->iriConverter ->getIriFromResourceClass ($ resourceClass );
91
- } else {
92
- $ data ['@id ' ] = $ this ->iriConverter ->getIriFromResource ($ resourceClass , UrlGeneratorInterface::ABS_PATH , $ context ['operation ' ] ?? null , $ context );
93
- }
94
-
81
+ $ data ['@id ' ] = $ this ->iriConverter ->getIriFromResource ($ resourceClass , UrlGeneratorInterface::ABS_PATH , $ context ['operation ' ] ?? null , $ context );
95
82
$ data ['@type ' ] = 'hydra:Collection ' ;
96
83
$ data ['hydra:member ' ] = [];
97
84
$ iriOnly = $ context [self ::IRI_ONLY ] ?? $ this ->defaultContext [self ::IRI_ONLY ];
98
85
unset($ context ['operation ' ], $ context ['operation_name ' ], $ context ['uri_variables ' ]);
99
86
100
87
foreach ($ object as $ obj ) {
101
88
if ($ iriOnly ) {
102
- $ data ['hydra:member ' ][] = $ this ->iriConverter instanceof LegacyIriConverterInterface ? $ this -> iriConverter -> getIriFromItem ( $ obj ) : $ this -> iriConverter ->getIriFromResource ($ obj );
89
+ $ data ['hydra:member ' ][] = $ this ->iriConverter ->getIriFromResource ($ obj );
103
90
} else {
104
91
$ data ['hydra:member ' ][] = $ this ->normalizer ->normalize ($ obj , $ format , $ context );
105
92
}
@@ -108,6 +95,7 @@ public function normalize($object, $format = null, array $context = []): array
108
95
if ($ object instanceof PaginatorInterface) {
109
96
$ data ['hydra:totalItems ' ] = $ object ->getTotalItems ();
110
97
}
98
+
111
99
if (\is_array ($ object ) || ($ object instanceof \Countable && !$ object instanceof PartialPaginatorInterface)) {
112
100
$ data ['hydra:totalItems ' ] = \count ($ object );
113
101
}
0 commit comments