Failed.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\process\exception;
  12. use think\Process;
  13. class Failed extends \RuntimeException
  14. {
  15. private $process;
  16. public function __construct(Process $process)
  17. {
  18. if ($process->isSuccessful()) {
  19. throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
  20. }
  21. $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText());
  22. if (!$process->isOutputDisabled()) {
  23. $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput());
  24. }
  25. parent::__construct($error);
  26. $this->process = $process;
  27. }
  28. public function getProcess()
  29. {
  30. return $this->process;
  31. }
  32. }