18
18
use ApiPlatform \Metadata \GraphQl \Operation as GraphQlOperation ;
19
19
use ApiPlatform \Metadata \GraphQl \Query ;
20
20
use ApiPlatform \Metadata \HttpOperation ;
21
- use ApiPlatform \Metadata \Link ;
22
21
use ApiPlatform \Metadata \Operation ;
23
22
use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
24
- use Psr \Container \ContainerInterface ;
25
23
26
24
trait LinksHandlerTrait
27
25
{
28
26
private ?ResourceMetadataCollectionFactoryInterface $ resourceMetadataCollectionFactory ;
29
- private ?ContainerInterface $ handleLinksLocator ;
30
27
31
28
/**
32
- * @return Link[]
29
+ * @param array{linkClass?: string, linkProperty?: string}&array<string, mixed> $context
30
+ *
31
+ * @return \ApiPlatform\Metadata\Link[]
33
32
*/
34
33
private function getLinks (string $ resourceClass , Operation $ operation , array $ context ): array
35
34
{
@@ -90,9 +89,12 @@ private function getLinks(string $resourceClass, Operation $operation, array $co
90
89
return [$ newLink ];
91
90
}
92
91
92
+ /**
93
+ * @param array<int|string,mixed> $identifiers
94
+ */
93
95
private function getIdentifierValue (array &$ identifiers , string $ name = null ): mixed
94
96
{
95
- if (isset ($ identifiers [$ name ])) {
97
+ if (null !== $ name && isset ($ identifiers [$ name ])) {
96
98
$ value = $ identifiers [$ name ];
97
99
unset($ identifiers [$ name ]);
98
100
@@ -102,6 +104,9 @@ private function getIdentifierValue(array &$identifiers, string $name = null): m
102
104
return array_shift ($ identifiers );
103
105
}
104
106
107
+ /**
108
+ * @return \ApiPlatform\Metadata\Link[]|array
109
+ */
105
110
private function getOperationLinks (Operation $ operation = null ): array
106
111
{
107
112
if ($ operation instanceof GraphQlOperation) {
@@ -114,22 +119,4 @@ private function getOperationLinks(Operation $operation = null): array
114
119
115
120
return [];
116
121
}
117
-
118
- private function getLinksHandler (Operation $ operation ): ?callable
119
- {
120
- if (!($ options = $ operation ->getStateOptions ()) || !method_exists ($ options , 'getHandleLinks ' ) || null === $ options ->getHandleLinks ()) {
121
- return null ;
122
- }
123
-
124
- $ handleLinks = $ options ->getHandleLinks (); // @phpstan-ignore-line method_exists called above
125
- if (\is_callable ($ handleLinks )) {
126
- return $ handleLinks ;
127
- }
128
-
129
- if ($ this ->handleLinksLocator && \is_string ($ handleLinks ) && $ this ->handleLinksLocator ->has ($ handleLinks )) {
130
- return [$ this ->handleLinksLocator ->get ($ handleLinks ), 'handleLinks ' ];
131
- }
132
-
133
- throw new RuntimeException (sprintf ('Could not find handleLinks service "%s" ' , $ handleLinks ));
134
- }
135
122
}
0 commit comments