-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent autowiring of required action paramreters
- Loading branch information
Dominic Tubach
committed
Dec 6, 2023
1 parent
ef4387d
commit 9af333d
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Civi/Funding/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,33 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Civi\Funding\DependencyInjection\Compiler; | ||
|
||
use Civi\Api4\Generic\AbstractAction; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Symfony DI tries to autowire properties annotated with @required. Though | ||
* CiviCRM actions parameters can be annotated in this way to make them | ||
* required. This pass clears the properties that are going to be injected for | ||
* action classes registered as service in the Civi\Funding\Api4\Action | ||
* namespace. | ||
* | ||
* @see https://github.com/symfony/symfony/pull/52910 | ||
*/ | ||
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\\Funding\\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