RunProcessMessageHandler.php 1003 B

123456789101112131415161718192021222324252627282930313233
  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 = new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout);
  22. try {
  23. return new RunProcessContext($message, $process->mustRun());
  24. } catch (ProcessFailedException $e) {
  25. throw new RunProcessFailedException($e, new RunProcessContext($message, $e->getProcess()));
  26. }
  27. }
  28. }