vendor/symfony/http-client/Chunk/ErrorChunk.php line 64

Open in your IDE?
  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\HttpClient\Chunk;
  11. use Symfony\Component\HttpClient\Exception\TransportException;
  12. use Symfony\Contracts\HttpClient\ChunkInterface;
  13. /**
  14.  * @author Nicolas Grekas <p@tchwork.com>
  15.  *
  16.  * @internal
  17.  */
  18. class ErrorChunk implements ChunkInterface
  19. {
  20.     private $didThrow false;
  21.     private $offset;
  22.     private $errorMessage;
  23.     private $error;
  24.     /**
  25.      * @param \Throwable|string $error
  26.      */
  27.     public function __construct(int $offset$error)
  28.     {
  29.         $this->offset $offset;
  30.         if (\is_string($error)) {
  31.             $this->errorMessage $error;
  32.         } else {
  33.             $this->error $error;
  34.             $this->errorMessage $error->getMessage();
  35.         }
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function isTimeout(): bool
  41.     {
  42.         $this->didThrow true;
  43.         if (null !== $this->error) {
  44.             throw new TransportException($this->errorMessage0$this->error);
  45.         }
  46.         return true;
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function isFirst(): bool
  52.     {
  53.         $this->didThrow true;
  54.         throw new TransportException($this->errorMessage0$this->error);
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function isLast(): bool
  60.     {
  61.         $this->didThrow true;
  62.         throw new TransportException($this->errorMessage0$this->error);
  63.     }
  64.     /**
  65.      * {@inheritdoc}
  66.      */
  67.     public function getInformationalStatus(): ?array
  68.     {
  69.         $this->didThrow true;
  70.         throw new TransportException($this->errorMessage0$this->error);
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public function getContent(): string
  76.     {
  77.         $this->didThrow true;
  78.         throw new TransportException($this->errorMessage0$this->error);
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     public function getOffset(): int
  84.     {
  85.         return $this->offset;
  86.     }
  87.     /**
  88.      * {@inheritdoc}
  89.      */
  90.     public function getError(): ?string
  91.     {
  92.         return $this->errorMessage;
  93.     }
  94.     /**
  95.      * @return bool Whether the wrapped error has been thrown or not
  96.      */
  97.     public function didThrow(): bool
  98.     {
  99.         return $this->didThrow;
  100.     }
  101.     public function __sleep()
  102.     {
  103.         throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
  104.     }
  105.     public function __wakeup()
  106.     {
  107.         throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
  108.     }
  109.     public function __destruct()
  110.     {
  111.         if (!$this->didThrow) {
  112.             $this->didThrow true;
  113.             throw new TransportException($this->errorMessage0$this->error);
  114.         }
  115.     }
  116. }