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

Appearance settings

Commit 7fa78fe

Browse filesBrowse files
committed
feature #17824 [FrameworkBundle][Workflow] Register alias for argument for workflow services with workflow name only (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle][Workflow] Register alias for argument for workflow services with workflow name only Fixes #17812 Commits ------- 79358aa [FrameworkBundle][Workflow] Register alias for argument for workflow services with workflow name only
2 parents 3ef569f + 79358aa commit 7fa78fe
Copy full SHA for 7fa78fe

File tree

Expand file treeCollapse file tree

1 file changed

+29
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-4
lines changed

‎workflow.rst

Copy file name to clipboardExpand all lines: workflow.rst
+29-4Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,9 @@ machine type, use ``camelCased workflow name + StateMachine``::
248248

249249
class MyClass
250250
{
251-
private $blogPublishingWorkflow;
252-
253251
// Symfony will inject the 'blog_publishing' workflow configured before
254-
public function __construct(WorkflowInterface $blogPublishingWorkflow)
252+
public function __construct(private readonly WorkflowInterface $blogPublishingWorkflow)
255253
{
256-
$this->blogPublishingWorkflow = $blogPublishingWorkflow;
257254
}
258255

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

268+
Workflows can also be injected thanks to their name and the
269+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Target`
270+
attribute::
271+
272+
use App\Entity\BlogPost;
273+
use Symfony\Component\DependencyInjection\Attribute\Target;
274+
use Symfony\Component\Workflow\WorkflowInterface;
275+
276+
class MyClass
277+
{
278+
public function __construct(
279+
#[Target('blog_publishing')]
280+
private readonly WorkflowInterface $workflow
281+
) {
282+
}
283+
284+
// ...
285+
}
286+
287+
This allows you to decorrelate the argument name of any implementation
288+
name.
289+
271290
.. versionadded:: 6.2
272291

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

294+
.. versionadded:: 6.3
295+
296+
Injecting a workflow with only its name and
297+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Target` was
298+
introduced in Symfony 6.3.
299+
275300
.. tip::
276301

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.