RunProcessMessageHandler.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. use Symfony\Component\Process\Exception\ProcessFailedException;
  12. use Symfony\Component\Process\Exception\RunProcessFailedException;
  13. use Symfony\Component\Process\Process;
  14. /**
  15. * @author Kevin Bond <kevinbond@gmail.com>
  16. */
  17. final class RunProcessMessageHandler
  18. {
  19. public function __invoke(RunProcessMessage $message): RunProcessContext
  20. {
  21. $process = match ($message->commandLine) {
  22. null => new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout),
  23. default => Process::fromShellCommandline($message->commandLine, $message->cwd, $message->env, $message->input, $message->timeout),
  24. };
  25. try {
  26. return new RunProcessContext($message, $process->mustRun());
  27. } catch (ProcessFailedException $e) {
  28. throw new RunProcessFailedException($e, new RunProcessContext($message, $e->getProcess()));
  29. }
  30. }
  31. }