StreamInterface.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace Guzzle\Stream;
  3. /**
  4. * OO interface to PHP streams
  5. */
  6. interface StreamInterface
  7. {
  8. /**
  9. * Convert the stream to a string if the stream is readable and the stream is seekable.
  10. *
  11. * @return string
  12. */
  13. public function __toString();
  14. /**
  15. * Close the underlying stream
  16. */
  17. public function close();
  18. /**
  19. * Get stream metadata
  20. *
  21. * @param string $key Specific metadata to retrieve
  22. *
  23. * @return array|mixed|null
  24. */
  25. public function getMetaData($key = null);
  26. /**
  27. * Get the stream resource
  28. *
  29. * @return resource
  30. */
  31. public function getStream();
  32. /**
  33. * Set the stream that is wrapped by the object
  34. *
  35. * @param resource $stream Stream resource to wrap
  36. * @param int $size Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.
  37. *
  38. * @return self
  39. */
  40. public function setStream($stream, $size = null);
  41. /**
  42. * Detach the current stream resource
  43. *
  44. * @return self
  45. */
  46. public function detachStream();
  47. /**
  48. * Get the stream wrapper type
  49. *
  50. * @return string
  51. */
  52. public function getWrapper();
  53. /**
  54. * Wrapper specific data attached to this stream.
  55. *
  56. * @return array
  57. */
  58. public function getWrapperData();
  59. /**
  60. * Get a label describing the underlying implementation of the stream
  61. *
  62. * @return string
  63. */
  64. public function getStreamType();
  65. /**
  66. * Get the URI/filename associated with this stream
  67. *
  68. * @return string
  69. */
  70. public function getUri();
  71. /**
  72. * Get the size of the stream if able
  73. *
  74. * @return int|bool
  75. */
  76. public function getSize();
  77. /**
  78. * Check if the stream is readable
  79. *
  80. * @return bool
  81. */
  82. public function isReadable();
  83. /**
  84. * Check if the stream is repeatable
  85. *
  86. * @return bool
  87. */
  88. public function isRepeatable();
  89. /**
  90. * Check if the stream is writable
  91. *
  92. * @return bool
  93. */
  94. public function isWritable();
  95. /**
  96. * Check if the stream has been consumed
  97. *
  98. * @return bool
  99. */
  100. public function isConsumed();
  101. /**
  102. * Alias of isConsumed
  103. *
  104. * @return bool
  105. */
  106. public function feof();
  107. /**
  108. * Check if the stream is a local stream vs a remote stream
  109. *
  110. * @return bool
  111. */
  112. public function isLocal();
  113. /**
  114. * Check if the string is repeatable
  115. *
  116. * @return bool
  117. */
  118. public function isSeekable();
  119. /**
  120. * Specify the size of the stream in bytes
  121. *
  122. * @param int $size Size of the stream contents in bytes
  123. *
  124. * @return self
  125. */
  126. public function setSize($size);
  127. /**
  128. * Seek to a position in the stream
  129. *
  130. * @param int $offset Stream offset
  131. * @param int $whence Where the offset is applied
  132. *
  133. * @return bool Returns TRUE on success or FALSE on failure
  134. * @link http://www.php.net/manual/en/function.fseek.php
  135. */
  136. public function seek($offset, $whence = SEEK_SET);
  137. /**
  138. * Read data from the stream
  139. *
  140. * @param int $length Up to length number of bytes read.
  141. *
  142. * @return string|bool Returns the data read from the stream or FALSE on failure or EOF
  143. */
  144. public function read($length);
  145. /**
  146. * Write data to the stream
  147. *
  148. * @param string $string The string that is to be written.
  149. *
  150. * @return int|bool Returns the number of bytes written to the stream on success or FALSE on failure.
  151. */
  152. public function write($string);
  153. /**
  154. * Returns the current position of the file read/write pointer
  155. *
  156. * @return int|bool Returns the position of the file pointer or false on error
  157. */
  158. public function ftell();
  159. /**
  160. * Rewind to the beginning of the stream
  161. *
  162. * @return bool Returns true on success or false on failure
  163. */
  164. public function rewind();
  165. /**
  166. * Read a line from the stream up to the maximum allowed buffer length
  167. *
  168. * @param int $maxLength Maximum buffer length
  169. *
  170. * @return string|bool
  171. */
  172. public function readLine($maxLength = null);
  173. /**
  174. * Set custom data on the stream
  175. *
  176. * @param string $key Key to set
  177. * @param mixed $value Value to set
  178. *
  179. * @return self
  180. */
  181. public function setCustomData($key, $value);
  182. /**
  183. * Get custom data from the stream
  184. *
  185. * @param string $key Key to retrieve
  186. *
  187. * @return null|mixed
  188. */
  189. public function getCustomData($key);
  190. }