@@ -131,7 +131,7 @@ private function encodeIriToCacheKey(string $iri): string
131
131
private function getResourceId (mixed $ privateField , object $ previousObject ): string
132
132
{
133
133
$ id = $ previousObject ->{'get ' .ucfirst ($ privateField )}()->getId ();
134
- if ($ id instanceof \Stringable) {
134
+ if ($ id instanceof \Stringable || is_numeric ( $ id ) ) {
135
135
return (string ) $ id ;
136
136
}
137
137
@@ -149,39 +149,61 @@ private function getCreatedOrUpdatedPayloads(object $object): array
149
149
$ resourceMetadata = $ this ->resourceMetadataCollectionFactory ->create ($ resourceClass );
150
150
$ shortName = $ resourceMetadata ->getOperation ()->getShortName ();
151
151
152
- $ mercure = $ resourceMetadata ->getOperation ()->getMercure () ?? false ;
153
- $ private = $ mercure ['private ' ] ?? false ;
154
- $ privateFieldsConfig = $ mercure ['private_fields ' ] ?? [];
155
- $ privateFieldData = [];
156
- if ($ private && $ privateFieldsConfig ) {
157
- foreach ($ privateFieldsConfig as $ privateField ) {
158
- $ privateFieldData ['__private_field_ ' .$ privateField ] = $ this ->getResourceId ($ privateField , $ object );
159
- }
160
- }
161
-
162
- $ iri = $ this ->iriConverter ->getIriFromResource ($ object );
163
- // Add collection subscriptions
164
- $ subscriptions = array_merge (
165
- $ this ->getSubscriptionsFromIri ($ this ->getCollectionIri ($ iri ), $ privateFieldData ),
166
- $ this ->getSubscriptionsFromIri ($ iri )
167
- );
168
-
169
152
$ payloads = [];
170
- foreach ($ subscriptions as [$ subscriptionId , $ subscriptionFields , $ subscriptionResult ]) {
171
- if ($ privateFieldData ) {
172
- $ fieldDiff = array_intersect_assoc ($ subscriptionFields , $ privateFieldData );
173
- if ($ fieldDiff !== $ privateFieldData ) {
153
+ foreach ($ resourceMetadata as $ apiResource ) {
154
+ foreach ($ apiResource ->getGraphQlOperations () as $ operation ) {
155
+ if (!$ operation instanceof Subscription) {
174
156
continue ;
175
157
}
176
- }
177
- $ resolverContext = ['fields ' => $ subscriptionFields , 'is_collection ' => false , 'is_mutation ' => false , 'is_subscription ' => true ];
178
- $ operation = (new Subscription ())->withName ('mercure_subscription ' )->withShortName ($ shortName );
179
- $ data = $ this ->normalizeProcessor ->process ($ object , $ operation , [], $ resolverContext );
180
-
181
- unset($ data ['clientSubscriptionId ' ]);
158
+ $ mercure = $ resourceMetadata ->getOperation ()->getMercure () ?? false ;
159
+ $ operationMercure = $ operation ->getMercure () ?? false ;
160
+ if ($ mercure !== false && $ operationMercure !== false ) {
161
+ /** @noinspection SlowArrayOperationsInLoopInspection */
162
+ $ mercure = array_merge ($ mercure , $ operationMercure );
163
+ }
164
+ $ private = $ mercure ['private ' ] ?? false ;
165
+ $ privateFieldsConfig = $ mercure ['private_fields ' ] ?? [];
166
+ $ privateFieldData = [];
167
+ if ($ private && $ privateFieldsConfig ) {
168
+ foreach ($ privateFieldsConfig as $ privateField ) {
169
+ $ privateFieldData ['__private_field_ ' . $ privateField ] = $ this ->getResourceId (
170
+ $ privateField ,
171
+ $ object
172
+ );
173
+ }
174
+ }
182
175
183
- if ($ data !== $ subscriptionResult ) {
184
- $ payloads [] = [$ subscriptionId , $ data ];
176
+ $ iri = $ this ->iriConverter ->getIriFromResource ($ object );
177
+ // Add collection subscriptions
178
+ $ subscriptions = array_merge (
179
+ $ this ->getSubscriptionsFromIri ($ this ->getCollectionIri ($ iri ), $ privateFieldData ),
180
+ $ this ->getSubscriptionsFromIri ($ iri )
181
+ );
182
+
183
+ foreach ($ subscriptions as [$ subscriptionId , $ subscriptionFields , $ subscriptionResult ]) {
184
+ if ($ privateFieldData ) {
185
+ $ fieldDiff = array_intersect_assoc ($ subscriptionFields , $ privateFieldData );
186
+ if ($ fieldDiff !== $ privateFieldData ) {
187
+ continue ;
188
+ }
189
+ }
190
+ $ resolverContext = [
191
+ 'fields ' => $ subscriptionFields ,
192
+ 'is_collection ' => false ,
193
+ 'is_mutation ' => false ,
194
+ 'is_subscription ' => true
195
+ ];
196
+ $ subscriptionOperation = (new Subscription ())->withName ('mercure_subscription ' )->withShortName (
197
+ $ shortName
198
+ );
199
+ $ data = $ this ->normalizeProcessor ->process ($ object , $ subscriptionOperation , [], $ resolverContext );
200
+
201
+ unset($ data ['clientSubscriptionId ' ]);
202
+
203
+ if ($ data !== $ subscriptionResult ) {
204
+ $ payloads [] = [$ subscriptionId , $ data ];
205
+ }
206
+ }
185
207
}
186
208
}
187
209
0 commit comments