@@ -26,6 +26,9 @@ final class ResourceMetadataCollection extends \ArrayObject
26
26
{
27
27
private const GRAPHQL_PREFIX = 'g_ ' ;
28
28
private const HTTP_PREFIX = 'h_ ' ;
29
+ private const FORCE_COLLECTION = 'co_ ' ;
30
+ private const HTTP_OPERATION = 'ht_ ' ;
31
+
29
32
private array $ operationCache = [];
30
33
31
34
public function __construct (private readonly string $ resourceClass , array $ input = [])
@@ -36,12 +39,15 @@ public function __construct(private readonly string $resourceClass, array $input
36
39
public function getOperation (?string $ operationName = null , bool $ forceCollection = false , bool $ httpOperation = false ): Operation
37
40
{
38
41
$ operationName ??= '' ;
39
- if (isset ($ this ->operationCache [self ::HTTP_PREFIX .$ operationName ])) {
40
- return $ this ->operationCache [self ::HTTP_PREFIX .$ operationName ];
42
+ $ cachePrefix = ($ forceCollection ? self ::FORCE_COLLECTION : '' ).($ httpOperation ? self ::HTTP_OPERATION : '' );
43
+ $ httpCacheKey = self ::HTTP_PREFIX .$ cachePrefix .$ operationName ;
44
+ if (isset ($ this ->operationCache [$ httpCacheKey ])) {
45
+ return $ this ->operationCache [$ httpCacheKey ];
41
46
}
42
47
43
- if (isset ($ this ->operationCache [self ::GRAPHQL_PREFIX .$ operationName ])) {
44
- return $ this ->operationCache [self ::GRAPHQL_PREFIX .$ operationName ];
48
+ $ gqlCacheKey = self ::GRAPHQL_PREFIX .$ cachePrefix .$ operationName ;
49
+ if (isset ($ this ->operationCache [$ gqlCacheKey ])) {
50
+ return $ this ->operationCache [$ gqlCacheKey ];
45
51
}
46
52
47
53
$ it = $ this ->getIterator ();
@@ -56,26 +62,26 @@ public function getOperation(?string $operationName = null, bool $forceCollectio
56
62
$ method = $ operation ->getMethod () ?? HttpOperation::METHOD_GET ;
57
63
$ isGetOperation = HttpOperation::METHOD_GET === $ method || HttpOperation::METHOD_OPTIONS === $ method || HttpOperation::METHOD_HEAD === $ method ;
58
64
if ('' === $ operationName && $ isGetOperation && ($ forceCollection ? $ isCollection : !$ isCollection )) {
59
- return $ this ->operationCache [self :: HTTP_PREFIX . $ operationName ] = $ operation ;
65
+ return $ this ->operationCache [$ httpCacheKey ] = $ operation ;
60
66
}
61
67
62
68
if ($ name === $ operationName ) {
63
- return $ this ->operationCache [self :: HTTP_PREFIX . $ operationName ] = $ operation ;
69
+ return $ this ->operationCache [$ httpCacheKey ] = $ operation ;
64
70
}
65
71
66
72
if ($ operation ->getUriTemplate () === $ operationName ) {
67
- return $ this ->operationCache [self :: HTTP_PREFIX . $ operationName ] = $ operation ;
73
+ return $ this ->operationCache [$ httpCacheKey ] = $ operation ;
68
74
}
69
75
}
70
76
71
77
foreach ($ metadata ->getGraphQlOperations () ?? [] as $ name => $ operation ) {
72
78
$ isCollection = $ operation instanceof CollectionOperationInterface;
73
79
if ('' === $ operationName && ($ forceCollection ? $ isCollection : !$ isCollection ) && false === $ httpOperation ) {
74
- return $ this ->operationCache [self :: GRAPHQL_PREFIX . $ operationName ] = $ operation ;
80
+ return $ this ->operationCache [$ gqlCacheKey ] = $ operation ;
75
81
}
76
82
77
83
if ($ name === $ operationName ) {
78
- return $ this ->operationCache [self :: GRAPHQL_PREFIX . $ operationName ] = $ operation ;
84
+ return $ this ->operationCache [$ httpCacheKey ] = $ operation ;
79
85
}
80
86
}
81
87
0 commit comments