菜谱项目

ProcessFailedException.php 1.4KB

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