Skip to content

[Workflow] Delete deprecated code examples #18248

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
May 4, 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
44 changes: 13 additions & 31 deletions workflow/workflow-and-state-machine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,51 +249,28 @@ Below is the configuration for the pull request state machine.
->to(['review']);
};

In a Symfony application using the
:ref:`default services.yaml configuration <service-container-services-load-example>`,
you can get this state machine by injecting the Workflow registry service::

// ...
use App\Entity\PullRequest;
use Symfony\Component\Workflow\Registry;

class SomeService
{
public function __construct(
private Registry $workflows,
) {
}

public function someMethod(PullRequest $pullRequest)
{
$stateMachine = $this->workflows->get($pullRequest, 'pull_request');
$stateMachine->apply($pullRequest, 'wait_for_review');
// ...
}

// ...
}

Symfony automatically creates a service for each workflow (:class:`Symfony\\Component\\Workflow\\Workflow`)
or state machine (:class:`Symfony\\Component\\Workflow\\StateMachine`) you
have defined in your configuration. This means that you can use ``workflow.pull_request``
or ``state_machine.pull_request`` respectively in your service definitions
to access the proper service::
have defined in your configuration. You can use the workflow inside a class by using
:doc:`service autowiring </service_container/autowiring>` and using
``camelCased workflow name + Workflow`` as parameter name. If it is a state
machine type, use ``camelCased workflow name + StateMachine``::

// ...
use App\Entity\PullRequest;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\WorkflowInterface;

class SomeService
{
public function __construct(
private StateMachine $stateMachine,
// Symfony will inject the 'pull_request' state machine configured before
private WorkflowInterface $pullRequestWorkflow,
) {
}

public function someMethod(PullRequest $pullRequest)
{
$this->stateMachine->apply($pullRequest, 'wait_for_review', [
$this->pullRequestWorkflow->apply($pullRequest, 'wait_for_review', [
'log_comment' => 'My logging comment for the wait for review transition.',
]);
// ...
Expand All @@ -302,6 +279,11 @@ to access the proper service::
// ...
}


.. versionadded:: 6.2

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

Automatic and Manual Validation
-------------------------------

Expand Down