ChunkInterface.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Contracts\HttpClient;
  11. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  12. /**
  13. * The interface of chunks returned by ResponseStreamInterface::current().
  14. *
  15. * When the chunk is first, last or timeout, the content MUST be empty.
  16. * When an unchecked timeout or a network error occurs, a TransportExceptionInterface
  17. * MUST be thrown by the destructor unless one was already thrown by another method.
  18. *
  19. * @author Nicolas Grekas <p@tchwork.com>
  20. *
  21. * @experimental in 1.1
  22. */
  23. interface ChunkInterface
  24. {
  25. /**
  26. * Tells when the idle timeout has been reached.
  27. *
  28. * @throws TransportExceptionInterface on a network error
  29. */
  30. public function isTimeout(): bool;
  31. /**
  32. * Tells when headers just arrived.
  33. *
  34. * @throws TransportExceptionInterface on a network error or when the idle timeout is reached
  35. */
  36. public function isFirst(): bool;
  37. /**
  38. * Tells when the body just completed.
  39. *
  40. * @throws TransportExceptionInterface on a network error or when the idle timeout is reached
  41. */
  42. public function isLast(): bool;
  43. /**
  44. * Returns a [status code, headers] tuple when a 1xx status code was just received.
  45. *
  46. * @throws TransportExceptionInterface on a network error or when the idle timeout is reached
  47. */
  48. public function getInformationalStatus(): ?array;
  49. /**
  50. * Returns the content of the response chunk.
  51. *
  52. * @throws TransportExceptionInterface on a network error or when the idle timeout is reached
  53. */
  54. public function getContent(): string;
  55. /**
  56. * Returns the offset of the chunk in the response body.
  57. */
  58. public function getOffset(): int;
  59. /**
  60. * In case of error, returns the message that describes it.
  61. */
  62. public function getError(): ?string;
  63. }