File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -191,8 +191,14 @@ class: Drupal\jsonapi\Routing\JsonApiParamEnhancer
191
191
192
192
$ service_map = $ container ->getByType (ServiceMap::class);
193
193
assert ($ service_map instanceof ServiceMap);
194
- // @todo this is not updating the reference in the container.
194
+ // @todo this is a hack that needs investigation.
195
+ // We cannot manipulate the service container and add parameters, so we take the existing
196
+ // service and modify it's properties so that its reference is updated within the container.
197
+ //
198
+ // During debug this works, but other times it fails.
195
199
$ service_map ->setDrupalServices ($ this ->serviceMap );
200
+ // So, to work around whatever is happening we force it into globals.
201
+ $ GLOBALS ['drupalServiceMap ' ] = $ service_map ->getServices ();
196
202
}
197
203
198
204
protected function loadLegacyIncludes (): void
Original file line number Diff line number Diff line change @@ -11,12 +11,25 @@ class ServiceMap
11
11
12
12
public function getService (string $ id ): ?DrupalServiceDefinition
13
13
{
14
+ // @see notes in DrupalAutoloader.
15
+ // This is all a work around due to inability to set container parameters.
14
16
if (count ($ this ->services ) === 0 ) {
15
- throw new ShouldNotHappenException ('No Drupal service map was registered. ' );
17
+ $ this ->services = $ GLOBALS ['drupalServiceMap ' ];
18
+ if (count ($ this ->services ) === 0 ) {
19
+ throw new ShouldNotHappenException ('No Drupal service map was registered. ' );
20
+ }
16
21
}
17
22
return $ this ->services [$ id ] ?? null ;
18
23
}
19
24
25
+ /**
26
+ * @return \PHPStan\Drupal\DrupalServiceDefinition[]
27
+ */
28
+ public function getServices (): array
29
+ {
30
+ return $ this ->services ;
31
+ }
32
+
20
33
public function setDrupalServices (array $ drupalServices ): void
21
34
{
22
35
$ this ->services = [];
You can’t perform that action at this time.
0 commit comments