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

[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

Merged
lyrixx merged 1 commit intosymfony:7.1fromlyrixx:workflow-dic-tag
Mar 11, 2024

Conversation

@lyrixx
Copy link
Member

@lyrixxlyrixx commentedAug 2, 2023
edited by nicolas-grekas
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
Tickets
LicenseMIT
Doc PR

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 thesupports configuration 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 theworkflow tag, not sub tags. To get it:

class Kernelextends BaseKernelimplements CompilerPassInterface{use MicroKernelTrait;publicfunctionprocess(ContainerBuilder$container)    {foreach ($container->findTaggedServiceIds('workflow.workflow')as$id =>$attributes) {$config =$container->getDefinition($id)->getTag('workflow')[0];dd($config);        }    }}

@nicolas-grekas
Copy link
Member

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
Copy link
MemberAuthor

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?

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])        ;    }}

Note

  1. I did not tested this very example
  2. Instead of an array of service, it would be better to use a service locator, but that's not the point here

@nicolas-grekas
Copy link
Member

Doesn't your registry duplicate the code we have in theRegistry class? Shouldn't we revert making it internal instead?
I'm challenging this because it feel strange to me to use tags for what you do here (I'm not sure we have any similar example).

@lyrixx
Copy link
MemberAuthor

lyrixx commentedAug 3, 2023
edited
Loading

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 itsWorkflowSupportStrategyInterface you can't build something totally dynamic, since you miss some information about the configuration

alexandre-daubois reacted with eyes emoji

javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull requestAug 3, 2023
…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
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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
Copy link
Member

Mouais, I'm not convinced.
The docs tell people the best way.
The Registry is the entry point for more powerful features.
If people want to shoot themselves in the foot, that's life.
So, I don't see why we need to have yet another way. I understand that one is userland and the other is internal, but still. If we're talking about edge cases, just using the current Registry should be enough, right?

@lyrixx
Copy link
MemberAuthor

I disagree. Registry needs instantiated workflow to work. It means no lazy loading.

Then you can't accesssupports configuration option.

That's two pain points that show the current way to work doesn't work well.

@lyrixx
Copy link
MemberAuthor

Rebased, and conflict fixed

@lyrixxlyrixxforce-pushed theworkflow-dic-tag branch 2 times, most recently fromee79817 to2527507CompareOctober 19, 2023 09:17
@lyrixx
Copy link
MemberAuthor

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 everyClient lays on the same entity. I could use the registry, but there is no lazy loading, so it will degrade performance.

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
Copy link
Member

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
Copy link
MemberAuthor

Hmm, Got it 👍🏼 We could document that the shape is not BC?

@stof
Copy link
Member

@lyrixx but then, how would you use it ?

@lyrixx
Copy link
MemberAuthor

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);

@lyrixxlyrixxforce-pushed theworkflow-dic-tag branch 2 times, most recently from682b35f to91c1f10CompareOctober 20, 2023 09:09
@nicolas-grekasnicolas-grekas removed this from the6.4 milestoneNov 15, 2023
@nicolas-grekasnicolas-grekas added this to the7.1 milestoneNov 15, 2023
@lyrixx
Copy link
MemberAuthor

lyrixx commentedNov 21, 2023
edited
Loading

Would you accept this PR if I inject in the tagonly the workflow metadata? It'll be enough.

@lyrixx
Copy link
MemberAuthor

Would you accept this PR if I inject in the tagonly the workflow metadata? It'll be enough.

cc@fabpot

@lyrixx
Copy link
MemberAuthor

PR rebased, and updated

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@fabpotfabpotAwaiting requested review from fabpot

@stofstofAwaiting requested review from stof

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

6 participants

@lyrixx@nicolas-grekas@fabpot@stof@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp