Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle][Workflow] Attach the workflow's configuration to theworkflow tag#51227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nicolas-grekas commentedAug 2, 2023
That's a bit strange to me, I'm not sure we ever did that. Usually tag attributes are used in a compiler pass. Shouldn't we do the same here? What's the more extended use case for this? |
lyrixx commentedAug 2, 2023
It looks like you missed the PR description :D The example show a usage of tag attribute in a compiler pass And the use case is described in the PR description too. But to go a bit further class Kernelextends BaseKernelimplements CompilerPassInterface{use MicroKernelTrait;publicfunctionprocess(ContainerBuilder$container) {$classesToWorkflow = [];foreach ($container->findTaggedServiceIds('workflow.workflow')as$id =>$attributes) {$config =$container->getDefinition($id)->getTag('workflow')[0];foreach ($config['supports'] ?? []as$class) {$classesToWorkflow[$class] =newReference($id); } }$container->register(MyRegistry::class, MyRegistry::class) ->setArguments([$classesToWorkflow]) ; }}
|
nicolas-grekas commentedAug 3, 2023
Doesn't your registry duplicate the code we have in the |
lyrixx commentedAug 3, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I have a big issue with the registry: People use it to get one workflow. In the documentation we used to tell to do : $workflowRegistry->get($subject)->apply($subject,'foobar'); And this is wrong: people must inject the right Workflow directly (law of demeter, performance, etc) That's why I decided to make it internal initially. The documentation has been updated since (I just checked, and there is stillone occurrence, cc@alexandre-daubois) But there is still one issue. If you have generic controller / service where you cannot know in advance which workflow to use, you have to use a ServiceLocator. There are all tagged, by name, so it should be easy... BUT, sometime, (cfthis discussion) the name is not enough. With this PR, people will have full power to build their own registry. It'll be faster, cleaner, and build exactly for each use case. Even with the current Registry and its |
…urrences (alexandre-daubois)This PR was merged into the 5.4 branch.Discussion----------[Workflow] Remove registry workflow retrieval occurrencesFollow-up ofsymfony/symfony#51227 (comment), `@lyrixx` proposed to remove "registry retrieval" occurrences in the documentation. Actually, the `Alternatively, use the registry...` part isn't present already in the 6.3 documentation.Commits-------aea773c [Workflow] Remove registry workflow retrieval occurrences
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OK, thanks for the explanations. I guess I would prefer wiring the registry (ours) in a compiler pass instead of doing it in FWB, but that can be done separately.
fabpot commentedAug 4, 2023
Mouais, I'm not convinced. |
lyrixx commentedAug 4, 2023
I disagree. Registry needs instantiated workflow to work. It means no lazy loading. Then you can't access That's two pain points that show the current way to work doesn't work well. |
lyrixx commentedAug 8, 2023
Rebased, and conflict fixed |
ee79817 to2527507Comparelyrixx commentedOct 19, 2023
Hello, This PR is ready and I have rebased it. @fabpot I understand your concern. But I have a real use case where I need to fetch a workflow dynamically based on some entity properties. We'll have a LOT of workflows - basically one by client (B to B to C), and every Finally, the diff is very minimal, and does not really impact the framework. Everything is thrown after the compilation. I don't really how it could hurt 🤓 |
stof commentedOct 19, 2023
The issue is that if we start exposing this config on the attribute with the intent of allowing projects to read it, we must provide BC on the structure of this config (with no way at all to ever deprecate anything in it as it is not accessed through a dedicated API in which we can trigger deprecations) |
lyrixx commentedOct 19, 2023
Hmm, Got it 👍🏼 We could document that the shape is not BC? |
stof commentedOct 19, 2023
@lyrixx but then, how would you use it ? |
lyrixx commentedOct 19, 2023
Basically with something like this: # config/packages/workflow.yamlframework:workflows:my_workflow_name:metadata:features:[repair, wash, dry] // src/Kernel.phpclass Kernelextends BaseKernelimplements CompilerPassInterface{use MicroKernelTrait;publicfunctionprocess(ContainerBuilder$container) {$configurations = [];foreach ($container->findTaggedServiceIds('workflow')as$id =>$config) {$configurations[$id] =$config[0]['config']; }$container ->getDefinition(Selector::class) ->setArgument('$configurations',$configurations) ; }} <?php// src/Workflow/Selector.phpnamespaceApp\Workflow;usePsr\Container\ContainerInterface;useSymfony\Component\DependencyInjection\Attribute\TaggedLocator;class Selector{publicfunction__construct( #[TaggedLocator('workflow')]privatereadonlyContainerInterface$container,privatereadonlyarray$configurations, ) { }publicfunctiongetWorkflow(/** Article $article */) {foreach ($this->configurationsas$id =>$config) {// $features = $article->getWorkflowFeatures();$featuresRequired = ['repair','wash','dry'];sort($featuresRequired);$featuresAvailable =$config['metadata']['features'] ?? [];sort($featuresAvailable);if ($featuresRequired ===$featuresAvailable) {return$this->container->get($id); } }thrownew \RuntimeException('No workflow found'); }} and finally publicfunction index(Selector$selector,Article$article):Response {$w =$selector->getWorkflow($article);dd($w); |
682b35f to91c1f10Comparelyrixx commentedNov 21, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Would you accept this PR if I inject in the tagonly the workflow metadata? It'll be enough. |
lyrixx commentedJan 29, 2024
cc@fabpot |
lyrixx commentedFeb 8, 2024
PR rebased, and updated |
Uh oh!
There was an error while loading.Please reload this page.
Since the registry is deprecated, users have to build their own registry when a service locator is not enough.
However, some information can be missing, like the
supportsconfiguration option.In this PR, I add the whole configuration to the tag, so everyone can build exactly what they need.
The config is added only to the
workflowtag, not sub tags. To get it: