@@ -248,12 +248,9 @@ machine type, use ``camelCased workflow name + StateMachine``::
248
248
249
249
class MyClass
250
250
{
251
- private $blogPublishingWorkflow;
252
-
253
251
// Symfony will inject the 'blog_publishing' workflow configured before
254
- public function __construct(WorkflowInterface $blogPublishingWorkflow)
252
+ public function __construct(private readonly WorkflowInterface $blogPublishingWorkflow)
255
253
{
256
- $this->blogPublishingWorkflow = $blogPublishingWorkflow;
257
254
}
258
255
259
256
public function toReview(BlogPost $post)
@@ -268,10 +265,38 @@ machine type, use ``camelCased workflow name + StateMachine``::
268
265
}
269
266
}
270
267
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
+
271
290
.. versionadded :: 6.2
272
291
273
292
All workflows and state machines services are tagged since in Symfony 6.2.
274
293
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
+
275
300
.. tip ::
276
301
277
302
If you want to retrieve all workflows, for documentation purposes for example,
0 commit comments