+ */
+class WorkflowValidatorPass implements CompilerPassInterface
+{
+ public function process(ContainerBuilder $container): void
+ {
+ foreach ($container->findTaggedServiceIds('workflow') as $attributes) {
+ foreach ($attributes as $attribute) {
+ foreach ($attribute['definition_validators'] ?? [] as $validatorClass) {
+ $container->addResource(new FileResource($container->getReflectionClass($validatorClass)->getFileName()));
+
+ $realDefinition = $container->get($attribute['definition_id'] ?? throw new \LogicException('The "definition_id" attribute is required.'));
+ (new $validatorClass())->validate($realDefinition, $attribute['name'] ?? throw new \LogicException('The "name" attribute is required.'));
+ }
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Component/Workflow/Tests/DependencyInjection/WorkflowValidatorPassTest.php b/src/Symfony/Component/Workflow/Tests/DependencyInjection/WorkflowValidatorPassTest.php
new file mode 100644
index 0000000000000..213e0d4d94cc3
--- /dev/null
+++ b/src/Symfony/Component/Workflow/Tests/DependencyInjection/WorkflowValidatorPassTest.php
@@ -0,0 +1,74 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Workflow\Tests\DependencyInjection;
+
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\Workflow\Definition;
+use Symfony\Component\Workflow\DependencyInjection\WorkflowValidatorPass;
+use Symfony\Component\Workflow\Validator\DefinitionValidatorInterface;
+use Symfony\Component\Workflow\WorkflowInterface;
+
+class WorkflowValidatorPassTest extends TestCase
+{
+ private ContainerBuilder $container;
+ private WorkflowValidatorPass $compilerPass;
+
+ protected function setUp(): void
+ {
+ $this->container = new ContainerBuilder();
+ $this->compilerPass = new WorkflowValidatorPass();
+ }
+
+ public function testNothingToDo()
+ {
+ $this->compilerPass->process($this->container);
+
+ $this->assertFalse(DefinitionValidator::$called);
+ }
+
+ public function testValidate()
+ {
+ $this
+ ->container
+ ->register('my.workflow', WorkflowInterface::class)
+ ->addTag('workflow', [
+ 'definition_id' => 'my.workflow.definition',
+ 'name' => 'my.workflow',
+ 'definition_validators' => [DefinitionValidator::class],
+ ])
+ ;
+
+ $this
+ ->container
+ ->register('my.workflow.definition', Definition::class)
+ ->setArguments([
+ '$places' => [],
+ '$transitions' => [],
+ ])
+ ;
+
+ $this->compilerPass->process($this->container);
+
+ $this->assertTrue(DefinitionValidator::$called);
+ }
+}
+
+class DefinitionValidator implements DefinitionValidatorInterface
+{
+ public static bool $called = false;
+
+ public function validate(Definition $definition, string $name): void
+ {
+ self::$called = true;
+ }
+}
diff --git a/src/Symfony/Component/Workflow/composer.json b/src/Symfony/Component/Workflow/composer.json
index ef6779c6de142..3e2c50a38cffd 100644
--- a/src/Symfony/Component/Workflow/composer.json
+++ b/src/Symfony/Component/Workflow/composer.json
@@ -25,6 +25,7 @@
},
"require-dev": {
"psr/log": "^1|^2|^3",
+ "symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/error-handler": "^6.4|^7.0",
"symfony/event-dispatcher": "^6.4|^7.0",
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy