-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix autowiring of APIv4 action classes
- Loading branch information
Dominic Tubach
committed
Feb 28, 2024
1 parent
37228e0
commit 4e2854f
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Civi/Civioffice/DependencyInjection/Compiler/ActionPropertyAutowireFixPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Civi\Civioffice\DependencyInjection\Compiler; | ||
|
||
use Civi\Api4\Generic\AbstractAction; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Symfony DI (v5 and v6) tries to autowire properties annotated with @required. | ||
* Though CiviCRM action parameters can be annotated in this way to make them | ||
* mandatory. This pass clears the properties that are going to be injected for | ||
* APIv4 action classes registered as services in the | ||
* Civi\Civioffice\Api4\Action namespace. (In Symfony DI v7 support of | ||
* annotations is dropped in favor of PHP attributes.) | ||
*/ | ||
final class ActionPropertyAutowireFixPass implements CompilerPassInterface { | ||
|
||
public function process(ContainerBuilder $container): void { | ||
foreach ($container->getDefinitions() as $id => $definition) { | ||
if ([] === $definition->getProperties() || !str_starts_with($id, 'Civi\\Civioffice\\Api4\\Action\\')) { | ||
continue; | ||
} | ||
|
||
if (is_a($id, AbstractAction::class, TRUE)) { | ||
$definition->setProperties([]); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters