-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Mark registry as internal and deprecate the service #46000
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
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.
Makes sense to me.
we should also deprecate the corresponding autowiring alias:
src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.php: ->alias(Registry::class, 'workflow.registry')
src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php
Outdated
Show resolved
Hide resolved
@lyrixx Do you have time to finish this one? |
Yes, I'll do that ASAP, But I'm on holidays for 2 weeks. I'll do that after! |
Registry
as internal and add a ServiceLocator
Hello, I pushed a new version without the service locator. I also updated the PR description with the new usage |
Instead, all workflow services are tagged and can be injected with the following YAML syntax: ```yaml !tagged_locator { tag: workflow, index_by: name } ``` or PHP syntax: ```php tagged_locator('workflow', 'name') ``` Also, two others tags exists for each workflow types * `workflow.workflow` * `workflow.state_machine`
Thank you @lyrixx. |
This PR was merged into the 6.2 branch. Discussion ---------- [FrameworkBundle] clean up unused variables | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | spotted while reviewing #46000 Commits ------- ccfb1e5 clean up unused variables
I'm in the category of programmers that injected the workflow registry in order to get a list of workflows in a helper bundle for workflow. // now deprecated, following https://symfony.com/doc/current/workflow.html#accessing-the-workflow-in-a-class
class WorkflowHelperService
{
public function __construct(
private Registry $workflowRegistry,
// in loadExtension of the bundle:
$builder->autowire( WorkflowHelperService::class)
->setArgument('$workflowRegistry', new Reference('workflow.registry'));
// better way
class WorkflowHelperService
{
public function __construct(
private ServiceLocator $locator,
// loadExtension()
$builder->autowire( WorkflowHelperService::class)
->setArgument('$locator', tagged_locator(tag: 'workflow', indexAttribute: 'name' ))
->setAutoconfigured(true)
; Using this, I'm not getting any services in the locator, $this->locator->count() is zero. I imagine I'm not using tagger_locator correctly, or I'm doing this in the wrong spot (I'm doing this in loadExtension of my bundle, perhaps it needs to be done in the compiler pass? If so, could you point me in the right direction on how to do that, I still find the bundle interactions a bit intimidating. |
Also, is this the right spot for that question? The issue itself is closed, should I open a new one? |
You should open a new discussion |
This is not recommended since symfony/symfony#46000
This PR was merged into the 6.2 branch. Discussion ---------- [Workflow] Do not talk about registry This is not recommended since symfony/symfony#46000 Commits ------- e169f78 [Workflow] Do not talk about registry
The Registry was added to be able to get a workflow easily from twig templates
without having to specify the workflow name.
Unfortunately, many people thought this was the only way to get a workflow and
we even add some flexibility to retrieve the workflow from the registry.
I think it's a bad idea to inject the registry, it has the same default as
injecting the Container: It's a black box, does not respect SOLID principle and
the demeter law, and make testing harder.
So I decided to mark the registry as internal. Instead people have to inject the
"right" workflow where they need it.
It can be legit to need all workflows, for documentation or for testing.
So, all workflow services are tagged and can be injected with the
following YAML syntax:
!tagged_locator { tag: workflow, index_by: name }
or PHP syntax:
Also, two others tags exists for each workflow types
workflow.workflow
workflow.state_machine