ProcessFailedException.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Exception;
  11. use Symfony\Component\Process\Process;
  12. /**
  13. * Exception for failed processes.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class ProcessFailedException extends RuntimeException
  18. {
  19. private $process;
  20. public function __construct(Process $process)
  21. {
  22. if ($process->isSuccessful()) {
  23. throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
  24. }
  25. parent::__construct(
  26. sprintf(
  27. 'The command "%s" failed.'."\nExit Code: %s(%s)\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
  28. $process->getCommandLine(),
  29. $process->getExitCode(),
  30. $process->getExitCodeText(),
  31. $process->getOutput(),
  32. $process->getErrorOutput()
  33. )
  34. );
  35. $this->process = $process;
  36. }
  37. public function getProcess()
  38. {
  39. return $this->process;
  40. }
  41. }