Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1636505

Browse files
committed
[Workflow] Add a way to add more definition validator
1 parent78c6ceb commit1636505

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
useSymfony\Component\Webhook\Controller\WebhookController;
184184
useSymfony\Component\WebLink\HttpHeaderSerializer;
185185
useSymfony\Component\Workflow;
186+
useSymfony\Component\Workflow\Validator\ConfiguredDefinitionValidatorInterface;
186187
useSymfony\Component\Workflow\WorkflowInterface;
187188
useSymfony\Component\Yaml\Command\LintCommandasBaseYamlLintCommand;
188189
useSymfony\Component\Yaml\Yaml;
@@ -1010,6 +1011,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
10101011
$definitionDefinition->addArgument($transitions);
10111012
$definitionDefinition->addArgument($initialMarking);
10121013
$definitionDefinition->addArgument(newReference(sprintf('%s.metadata_store',$workflowId)));
1014+
$definitionDefinition->addTag('workflow.definition', ['name' =>$name]);
10131015

10141016
// Create MarkingStore
10151017
$markingStoreDefinition =null;
@@ -1104,6 +1106,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11041106
$container->setParameter('workflow.has_guard_listeners',true);
11051107
}
11061108
}
1109+
1110+
$container->registerForAutoconfiguration(ConfiguredDefinitionValidatorInterface::class)
1111+
->addTag('workflow.definition_validator');
11071112
}
11081113

11091114
privatefunctionregisterDebugConfiguration(array$config,ContainerBuilder$container,PhpFileLoader$loader):void

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
useSymfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
7171
useSymfony\Component\VarExporter\Internal\Hydrator;
7272
useSymfony\Component\VarExporter\Internal\Registry;
73+
useSymfony\Component\Workflow\DependencyInjection\DefinitionValidatorPass;
7374
useSymfony\Component\Workflow\DependencyInjection\WorkflowDebugPass;
7475
useSymfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass;
7576

@@ -158,6 +159,7 @@ public function build(ContainerBuilder $container): void
158159
$container->addCompilerPass(newCachePoolPrunerPass(), PassConfig::TYPE_AFTER_REMOVING);
159160
$this->addCompilerPassIfExists($container, FormPass::class);
160161
$this->addCompilerPassIfExists($container, WorkflowGuardListenerPass::class);
162+
$this->addCompilerPassIfExists($container, DefinitionValidatorPass::class);
161163
$container->addCompilerPass(newResettableServicePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
162164
$container->addCompilerPass(newRegisterLocaleAwareServicesPass());
163165
$container->addCompilerPass(newTestServiceContainerWeakRefPass(), PassConfig::TYPE_BEFORE_REMOVING, -32);

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
useSymfony\Component\Workflow\CacheWarmer\DefinitionValidatorCacheWarmer;
1415
useSymfony\Component\Workflow\EventListener\ExpressionLanguage;
1516
useSymfony\Component\Workflow\MarkingStore\MethodMarkingStore;
1617
useSymfony\Component\Workflow\Registry;
@@ -42,5 +43,10 @@
4243
->set('workflow.registry', Registry::class)
4344
->alias(Registry::class,'workflow.registry')
4445
->set('workflow.security.expression_language', ExpressionLanguage::class)
46+
->set('workflow.cache_warmer.definition_validator', DefinitionValidatorCacheWarmer::class)
47+
->args([
48+
abstract_arg('definition and validators'),
49+
])
50+
->tag('kernel.cache_warmer')
4551
;
4652
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Workflow\CacheWarmer;
13+
14+
useSymfony\Component\Workflow\Definition;
15+
useSymfony\Component\Workflow\Validator\DefinitionValidatorInterface;
16+
17+
finalclass DefinitionAndValidator
18+
{
19+
publicfunction__construct(
20+
publicreadonlyDefinitionValidatorInterface$validator,
21+
publicreadonlyDefinition$definition,
22+
publicreadonlystring$name,
23+
) {
24+
}
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Workflow\CacheWarmer;
13+
14+
useSymfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
15+
16+
finalclass DefinitionValidatorCacheWarmerimplements CacheWarmerInterface
17+
{
18+
/**
19+
* @param iterable<DefinitionAndValidator> $definitionAndValidators
20+
*/
21+
publicfunction__construct(
22+
privatereadonlyiterable$definitionAndValidators,
23+
) {
24+
}
25+
26+
publicfunctionisOptional():bool
27+
{
28+
returnfalse;
29+
}
30+
31+
publicfunctionwarmUp(string$cacheDir, ?string$buildDir =null):array
32+
{
33+
foreach ($this->definitionAndValidatorsas$definitionAndValidator) {
34+
$definitionAndValidator
35+
->validator
36+
->validate($definitionAndValidator->definition,$definitionAndValidator->name)
37+
;
38+
}
39+
40+
return [];
41+
}
42+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Workflow\DependencyInjection;
13+
14+
useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
useSymfony\Component\DependencyInjection\ContainerBuilder;
16+
useSymfony\Component\DependencyInjection\Definition;
17+
useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException;
18+
useSymfony\Component\DependencyInjection\Reference;
19+
useSymfony\Component\Workflow\CacheWarmer\DefinitionAndValidator;
20+
useSymfony\Component\Workflow\Validator\ConfiguredDefinitionValidatorInterface;
21+
22+
/**
23+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
24+
*/
25+
class DefinitionValidatorPassimplements CompilerPassInterface
26+
{
27+
publicfunctionprocess(ContainerBuilder$container):void
28+
{
29+
if (!$container->hasDefinition('workflow.cache_warmer.definition_validator')) {
30+
return;
31+
}
32+
33+
$definitions = [];
34+
foreach ($container->findTaggedServiceIds('workflow.definition')as$id =>$attributes) {
35+
$name =$attributes[0]['name'] ??thrownewInvalidArgumentException(sprintf('The "name" attribute is mandatory for the "workflow.definition" tag. Check the tag for service "%s".',$id));
36+
$definitions[$name] =newReference($id);
37+
}
38+
39+
$definitionAndValidators = [];
40+
foreach ($container->findTaggedServiceIds('workflow.definition_validator')as$id =>$attributes) {
41+
$def =$container->getDefinition($id);
42+
43+
$class =$def->getClass();
44+
45+
if (!$r =$container->getReflectionClass($class)) {
46+
thrownewInvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.',$class,$id));
47+
}
48+
if (!$r->isSubclassOf(ConfiguredDefinitionValidatorInterface::class)) {
49+
thrownewInvalidArgumentException(sprintf('Service "%s" must implement interface "%s".',$id, ConfiguredDefinitionValidatorInterface::class));
50+
}
51+
52+
foreach ($class::getSupportedWorkflows()as$name) {
53+
if ('*' ===$name) {
54+
foreach ($definitionsas$definitionName =>$definition) {
55+
$definitionAndValidators[] =newDefinition(
56+
DefinitionAndValidator::class,
57+
[
58+
newReference($id),
59+
$definition,
60+
$definitionName,
61+
]
62+
);
63+
}
64+
}elseif (isset($definitions[$name])) {
65+
$definitionAndValidators[] =newDefinition(
66+
DefinitionAndValidator::class,
67+
[
68+
newReference($id),
69+
$definitions[$name],
70+
$name,
71+
]
72+
);
73+
}else {
74+
thrownewInvalidArgumentException(sprintf('The workflow "%s" does not exist. Check the "getConfiguration()" method of the service "%s".',$name,$id));
75+
}
76+
}
77+
}
78+
79+
$container
80+
->getDefinition('workflow.cache_warmer.definition_validator')
81+
->replaceArgument(0,$definitionAndValidators)
82+
;
83+
}
84+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Workflow\Validator;
13+
14+
/**
15+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
16+
*/
17+
interface ConfiguredDefinitionValidatorInterfaceextends DefinitionValidatorInterface
18+
{
19+
/**
20+
* @return list<string> A list of workflow name, or "*" for all workflows
21+
*/
22+
publicstaticfunctiongetSupportedWorkflows():iterable;
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp