RunProcessMessage.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Process\Messenger;
  11. /**
  12. * @author Kevin Bond <kevinbond@gmail.com>
  13. */
  14. class RunProcessMessage implements \Stringable
  15. {
  16. public ?string $commandLine = null;
  17. public function __construct(
  18. public readonly array $command,
  19. public readonly ?string $cwd = null,
  20. public readonly ?array $env = null,
  21. public readonly mixed $input = null,
  22. public readonly ?float $timeout = 60.0,
  23. ) {
  24. }
  25. public function __toString(): string
  26. {
  27. return $this->commandLine ?? implode(' ', $this->command);
  28. }
  29. /**
  30. * Create a process message instance that will instantiate a Process using the fromShellCommandline method.
  31. *
  32. * @see Process::fromShellCommandline
  33. */
  34. public static function fromShellCommandline(string $command, ?string $cwd = null, ?array $env = null, mixed $input = null, ?float $timeout = 60): self
  35. {
  36. $message = new self([], $cwd, $env, $input, $timeout);
  37. $message->commandLine = $command;
  38. return $message;
  39. }
  40. }