Skip to content

[Messenger][Process] add fromShellCommandLine() documentation #20681

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
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ You can configure the options passed to the ``other_options`` argument of
and ``suppress_errors``) are only supported on Windows operating systems.
Check out the `PHP documentation for proc_open()`_ before using them.

.. _process-using-features-from-the-os-shell:

Using Features From the OS Shell
--------------------------------

Expand Down
33 changes: 31 additions & 2 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2301,8 +2301,9 @@ will take care of creating a new process with the parameters you passed::

class CleanUpService
{
public function __construct(private readonly MessageBusInterface $bus)
{
public function __construct(
private readonly MessageBusInterface $bus,
) {
}

public function cleanUp(): void
Expand All @@ -2313,6 +2314,34 @@ will take care of creating a new process with the parameters you passed::
}
}

A static factory :method:`Symfony\\Component\\Process\\Messenger\\RunProcessMessage::fromShellCommandline` is also
available if you want to use features of your shell such as redirections or pipes::

use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Process\Messenger\RunProcessMessage;

class CleanUpService
{
public function __construct(
private readonly MessageBusInterface $bus,
) {
}

public function cleanUp(): void
{
$this->bus->dispatch(RunProcessMessage::fromShellCommandline('echo "Hello World" > var/log/hello.txt'));

// ...
}
}

For more information, see the
dedicated :ref:`Using Features From the OS Shell <process-using-features-from-the-os-shell>` documentation.

.. versionadded:: 7.3

The ``RunProcessMessage::fromShellCommandline()`` method was introduced in Symfony 7.3.

Once handled, the handler will return a
:class:`Symfony\\Component\\Process\\Messenger\\RunProcessContext` which
contains many useful information such as the exit code or the output of the
Expand Down