@@ -249,51 +249,28 @@ Below is the configuration for the pull request state machine.
249249 ->to(['review']);
250250 };
251251
252- In a Symfony application using the
253- :ref: `default services.yaml configuration <service-container-services-load-example >`,
254- you can get this state machine by injecting the Workflow registry service::
255-
256- // ...
257- use App\Entity\PullRequest;
258- use Symfony\Component\Workflow\Registry;
259-
260- class SomeService
261- {
262- public function __construct(
263- private Registry $workflows,
264- ) {
265- }
266-
267- public function someMethod(PullRequest $pullRequest)
268- {
269- $stateMachine = $this->workflows->get($pullRequest, 'pull_request');
270- $stateMachine->apply($pullRequest, 'wait_for_review');
271- // ...
272- }
273-
274- // ...
275- }
276-
277252 Symfony automatically creates a service for each workflow (:class: `Symfony\\ Component\\ Workflow\\ Workflow `)
278253or state machine (:class: `Symfony\\ Component\\ Workflow\\ StateMachine `) you
279- have defined in your configuration. This means that you can use ``workflow.pull_request ``
280- or ``state_machine.pull_request `` respectively in your service definitions
281- to access the proper service::
254+ have defined in your configuration. You can use the workflow inside a class by using
255+ :doc: `service autowiring </service_container/autowiring >` and using
256+ ``camelCased workflow name + Workflow `` as parameter name. If it is a state
257+ machine type, use ``camelCased workflow name + StateMachine ``::
282258
283259 // ...
284260 use App\Entity\PullRequest;
285- use Symfony\Component\Workflow\StateMachine ;
261+ use Symfony\Component\Workflow\WorkflowInterface ;
286262
287263 class SomeService
288264 {
289265 public function __construct(
290- private StateMachine $stateMachine,
266+ // Symfony will inject the 'pull_request' state machine configured before
267+ private WorkflowInterface $pullRequestWorkflow,
291268 ) {
292269 }
293270
294271 public function someMethod(PullRequest $pullRequest)
295272 {
296- $this->stateMachine ->apply($pullRequest, 'wait_for_review', [
273+ $this->pullRequestWorkflow ->apply($pullRequest, 'wait_for_review', [
297274 'log_comment' => 'My logging comment for the wait for review transition.',
298275 ]);
299276 // ...
@@ -302,6 +279,11 @@ to access the proper service::
302279 // ...
303280 }
304281
282+
283+ .. versionadded :: 6.2
284+
285+ All workflows and state machines services are tagged since in Symfony 6.2.
286+
305287Automatic and Manual Validation
306288-------------------------------
307289
0 commit comments