Stream.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace oauth2\components;
  3. use Yii;
  4. use yii\helpers\Json;
  5. use Psr\Http\Message\StreamInterface;
  6. /**
  7. * Class Stream
  8. * @package common\models\oauth2
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class Stream implements StreamInterface
  12. {
  13. /**
  14. * Reads all data from the stream into a string, from the beginning to end.
  15. *
  16. * This method MUST attempt to seek to the beginning of the stream before
  17. * reading data and read the stream until the end is reached.
  18. *
  19. * Warning: This could attempt to load a large amount of data into memory.
  20. *
  21. * This method MUST NOT raise an exception in order to conform with PHP's
  22. * string casting operations.
  23. *
  24. * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
  25. * @return string
  26. */
  27. public function __toString()
  28. {
  29. }
  30. /**
  31. * Closes the stream and any underlying resources.
  32. *
  33. * @return void
  34. */
  35. public function close()
  36. {
  37. }
  38. /**
  39. * Separates any underlying resources from the stream.
  40. *
  41. * After the stream has been detached, the stream is in an unusable state.
  42. *
  43. * @return resource|null Underlying PHP stream, if any
  44. */
  45. public function detach()
  46. {
  47. }
  48. /**
  49. * Get the size of the stream if known.
  50. *
  51. * @return int|null Returns the size in bytes if known, or null if unknown.
  52. */
  53. public function getSize()
  54. {
  55. }
  56. /**
  57. * Returns the current position of the file read/write pointer
  58. *
  59. * @return int Position of the file pointer
  60. * @throws \RuntimeException on error.
  61. */
  62. public function tell()
  63. {
  64. }
  65. /**
  66. * Returns true if the stream is at the end of the stream.
  67. *
  68. * @return bool
  69. */
  70. public function eof()
  71. {
  72. }
  73. /**
  74. * Returns whether or not the stream is seekable.
  75. *
  76. * @return bool
  77. */
  78. public function isSeekable()
  79. {
  80. }
  81. /**
  82. * Seek to a position in the stream.
  83. *
  84. * @link http://www.php.net/manual/en/function.fseek.php
  85. * @param int $offset Stream offset
  86. * @param int $whence Specifies how the cursor position will be calculated
  87. * based on the seek offset. Valid values are identical to the built-in
  88. * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
  89. * offset bytes SEEK_CUR: Set position to current location plus offset
  90. * SEEK_END: Set position to end-of-stream plus offset.
  91. * @throws \RuntimeException on failure.
  92. */
  93. public function seek($offset, $whence = SEEK_SET)
  94. {
  95. }
  96. /**
  97. * Seek to the beginning of the stream.
  98. *
  99. * If the stream is not seekable, this method will raise an exception;
  100. * otherwise, it will perform a seek(0).
  101. *
  102. * @see seek()
  103. * @link http://www.php.net/manual/en/function.fseek.php
  104. * @throws \RuntimeException on failure.
  105. */
  106. public function rewind()
  107. {
  108. }
  109. /**
  110. * Returns whether or not the stream is writable.
  111. *
  112. * @return bool
  113. */
  114. public function isWritable()
  115. {
  116. }
  117. /**
  118. * Write data to the stream.
  119. *
  120. * @param string $string The string that is to be written.
  121. * @return int Returns the number of bytes written to the stream.
  122. * @throws \RuntimeException on failure.
  123. */
  124. public function write($string)
  125. {
  126. if (!empty(json_decode($string))) {
  127. Yii::$app->response->data = Json::decode($string);
  128. } else {
  129. Yii::$app->response->data = $string;
  130. }
  131. }
  132. /**
  133. * Returns whether or not the stream is readable.
  134. *
  135. * @return bool
  136. */
  137. public function isReadable()
  138. {
  139. }
  140. /**
  141. * Read data from the stream.
  142. *
  143. * @param int $length Read up to $length bytes from the object and return
  144. * them. Fewer than $length bytes may be returned if underlying stream
  145. * call returns fewer bytes.
  146. * @return string Returns the data read from the stream, or an empty string
  147. * if no bytes are available.
  148. * @throws \RuntimeException if an error occurs.
  149. */
  150. public function read($length)
  151. {
  152. return strlen(Yii::$app->response->data);
  153. }
  154. /**
  155. * Returns the remaining contents in a string
  156. *
  157. * @return string
  158. * @throws \RuntimeException if unable to read or an error occurs while
  159. * reading.
  160. */
  161. public function getContents()
  162. {
  163. return Yii::$app->response->data;
  164. }
  165. /**
  166. * Get stream metadata as an associative array or retrieve a specific key.
  167. *
  168. * The keys returned are identical to the keys returned from PHP's
  169. * stream_get_meta_data() function.
  170. *
  171. * @link http://php.net/manual/en/function.stream-get-meta-data.php
  172. * @param string $key Specific metadata to retrieve.
  173. * @return array|mixed|null Returns an associative array if no key is
  174. * provided. Returns a specific key value if a key is provided and the
  175. * value is found, or null if the key is not found.
  176. */
  177. public function getMetadata($key = null)
  178. {
  179. }
  180. }
粤ICP备19079148号