ExceptionInterface.php
1 year ago
InvalidArgumentException.php
1 year ago
LogicException.php
1 year ago
ProcessFailedException.php
1 year ago
ProcessSignaledException.php
1 year ago
ProcessTimedOutException.php
1 year ago
RuntimeException.php
1 year ago
ProcessTimedOutException.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Symfony\Component\Process\Exception; |
| 12 | |
| 13 | use Symfony\Component\Process\Process; |
| 14 | /** |
| 15 | * Exception that is thrown when a process times out. |
| 16 | * |
| 17 | * @author Johannes M. Schmitt <schmittjoh@gmail.com> |
| 18 | */ |
| 19 | class ProcessTimedOutException extends \Symfony\Component\Process\Exception\RuntimeException |
| 20 | { |
| 21 | public const TYPE_GENERAL = 1; |
| 22 | public const TYPE_IDLE = 2; |
| 23 | private $process; |
| 24 | private $timeoutType; |
| 25 | public function __construct(Process $process, int $timeoutType) |
| 26 | { |
| 27 | $this->process = $process; |
| 28 | $this->timeoutType = $timeoutType; |
| 29 | parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout())); |
| 30 | } |
| 31 | public function getProcess() |
| 32 | { |
| 33 | return $this->process; |
| 34 | } |
| 35 | public function isGeneralTimeout() |
| 36 | { |
| 37 | return self::TYPE_GENERAL === $this->timeoutType; |
| 38 | } |
| 39 | public function isIdleTimeout() |
| 40 | { |
| 41 | return self::TYPE_IDLE === $this->timeoutType; |
| 42 | } |
| 43 | public function getExceededTimeout() |
| 44 | { |
| 45 | switch ($this->timeoutType) { |
| 46 | case self::TYPE_GENERAL: |
| 47 | return $this->process->getTimeout(); |
| 48 | case self::TYPE_IDLE: |
| 49 | return $this->process->getIdleTimeout(); |
| 50 | default: |
| 51 | throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 |