ProcessFailedException.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. $error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
  26. $process->getCommandLine(),
  27. $process->getExitCode(),
  28. $process->getExitCodeText()
  29. );
  30. if (!$process->isOutputDisabled()) {
  31. $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
  32. $process->getOutput(),
  33. $process->getErrorOutput()
  34. );
  35. }
  36. parent::__construct($error);
  37. $this->process = $process;
  38. }
  39. public function getProcess()
  40. {
  41. return $this->process;
  42. }
  43. }