Skip to content

[FrameworkBundle][Workflow] Register alias for argument for workflow services with workflow name only #17824

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

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,9 @@ machine type, use ``camelCased workflow name + StateMachine``::

class MyClass
{
private $blogPublishingWorkflow;

// Symfony will inject the 'blog_publishing' workflow configured before
public function __construct(WorkflowInterface $blogPublishingWorkflow)
public function __construct(private readonly WorkflowInterface $blogPublishingWorkflow)
{
$this->blogPublishingWorkflow = $blogPublishingWorkflow;
}

public function toReview(BlogPost $post)
Expand All @@ -268,10 +265,38 @@ machine type, use ``camelCased workflow name + StateMachine``::
}
}

Workflows can also be injected thanks to their name and the
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Target`
attribute::

use App\Entity\BlogPost;
use Symfony\Component\DependencyInjection\Attribute\Target;
use Symfony\Component\Workflow\WorkflowInterface;

class MyClass
{
public function __construct(
#[Target('blog_publishing')]
private readonly WorkflowInterface $workflow
) {
}

// ...
}

This allows you to decorrelate the argument name of any implementation
name.

.. versionadded:: 6.2

All workflows and state machines services are tagged since in Symfony 6.2.

.. versionadded:: 6.3

Injecting a workflow with only its name and
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Target` was
introduced in Symfony 6.3.

.. tip::

If you want to retrieve all workflows, for documentation purposes for example,
Expand Down