Commit a317ae1 Dominic Tubach
committed
1 parent 37228e0 commit a317ae1 Copy full SHA for a317ae1
File tree 2 files changed +36
-0
lines changed
Civi/Civioffice/DependencyInjection/Compiler
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types = 1 );
3
+
4
+ namespace Civi \Civioffice \DependencyInjection \Compiler ;
5
+
6
+ use Civi \Api4 \Generic \AbstractAction ;
7
+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
8
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
9
+
10
+ /**
11
+ * Symfony DI (v5 and v6) tries to autowire properties annotated with @required.
12
+ * Though CiviCRM action parameters can be annotated in this way to make them
13
+ * mandatory. This pass clears the properties that are going to be injected for
14
+ * APIv4 action classes registered as services in the
15
+ * Civi\Civioffice\Api4\Action namespace. (In Symfony DI v7 support of
16
+ * annotations is dropped in favor of PHP attributes.)
17
+ */
18
+ final class Api4ActionPropertyAutowireFixPass implements CompilerPassInterface {
19
+
20
+ public function process (ContainerBuilder $ container ): void {
21
+ foreach ($ container ->getDefinitions () as $ id => $ definition ) {
22
+ if ([] === $ definition ->getProperties () || !str_starts_with ($ id , 'Civi \\Civioffice \\Api4 \\Action \\' )) {
23
+ continue ;
24
+ }
25
+
26
+ if (is_a ($ id , AbstractAction::class, TRUE )) {
27
+ $ definition ->setProperties ([]);
28
+ }
29
+ }
30
+ }
31
+
32
+ }
Original file line number Diff line number Diff line change 21
21
/** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */
22
22
23
23
use Civi \Civioffice \Api4 \Action \Civioffice \RenderWebAction ;
24
+ use Civi \Civioffice \DependencyInjection \Compiler \Api4ActionPropertyAutowireFixPass ;
24
25
use Civi \Civioffice \EventSubscriber \ActivityCiviOfficeTokenSubscriber ;
25
26
use Civi \Civioffice \EventSubscriber \CaseCiviOfficeTokenSubscriber ;
26
27
use Civi \Civioffice \EventSubscriber \CiviOfficeSearchKitTaskSubscriber ;
31
32
use Civi \Civioffice \EventSubscriber \ParticipantCiviOfficeTokenSubscriber ;
32
33
use Civi \Civioffice \Render \Queue \RenderQueueBuilderFactory ;
33
34
use Civi \Civioffice \Render \Queue \RenderQueueRunner ;
35
+ use Symfony \Component \DependencyInjection \Compiler \PassConfig ;
34
36
35
37
if (!$ container ->has (\CRM_Queue_Service::class)) {
36
38
$ container ->autowire (\CRM_Queue_Service::class, \CRM_Queue_Service::class);
37
39
}
38
40
41
+ $ container ->addCompilerPass (new Api4ActionPropertyAutowireFixPass (), PassConfig::TYPE_BEFORE_REMOVING );
42
+
39
43
$ container ->autowire (RenderQueueBuilderFactory::class)
40
44
->setPublic (TRUE );
41
45
$ container ->autowire (RenderQueueRunner::class)
You can’t perform that action at this time.
0 commit comments