Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Process\Exception; Chris@0: Chris@0: use Symfony\Component\Process\Process; Chris@0: Chris@0: /** Chris@0: * Exception that is thrown when a process times out. Chris@0: * Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@0: class ProcessTimedOutException extends RuntimeException Chris@0: { Chris@0: const TYPE_GENERAL = 1; Chris@0: const TYPE_IDLE = 2; Chris@0: Chris@0: private $process; Chris@0: private $timeoutType; Chris@0: Chris@0: public function __construct(Process $process, $timeoutType) Chris@0: { Chris@0: $this->process = $process; Chris@0: $this->timeoutType = $timeoutType; Chris@0: Chris@0: parent::__construct(sprintf( Chris@0: 'The process "%s" exceeded the timeout of %s seconds.', Chris@0: $process->getCommandLine(), Chris@0: $this->getExceededTimeout() Chris@0: )); Chris@0: } Chris@0: Chris@0: public function getProcess() Chris@0: { Chris@0: return $this->process; Chris@0: } Chris@0: Chris@0: public function isGeneralTimeout() Chris@0: { Chris@14: return self::TYPE_GENERAL === $this->timeoutType; Chris@0: } Chris@0: Chris@0: public function isIdleTimeout() Chris@0: { Chris@14: return self::TYPE_IDLE === $this->timeoutType; Chris@0: } Chris@0: Chris@0: public function getExceededTimeout() Chris@0: { Chris@0: switch ($this->timeoutType) { Chris@0: case self::TYPE_GENERAL: Chris@0: return $this->process->getTimeout(); Chris@0: Chris@0: case self::TYPE_IDLE: Chris@0: return $this->process->getIdleTimeout(); Chris@0: Chris@0: default: Chris@0: throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); Chris@0: } Chris@0: } Chris@0: }