Skip to content

Commit f7a9ce9

Browse files
committed
Cleanup: Adds docblocks to StreamWrapperHook.
1 parent 772c4a2 commit f7a9ce9

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

src/VCR/LibraryHooks/StreamWrapperHook.php

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use VCR\Util\Assertion;
88

99
/**
10-
* StreamWrapper.
10+
* Library hook for streamWrapper functions using stream_wrapper_register().
1111
*/
1212
class StreamWrapperHook implements LibraryHook
1313
{
@@ -67,14 +67,35 @@ public function isEnabled()
6767
return $this->status == self::ENABLED;
6868
}
6969

70+
/**
71+
* This method is called immediately after the wrapper is initialized (f.e. by fopen() and file_get_contents()).
72+
*
73+
* @link http://www.php.net/manual/en/streamwrapper.stream-open.php
74+
* @param string $path Specifies the URL that was passed to the original function.
75+
* @param string $mode The mode used to open the file, as detailed for fopen().
76+
* @param int $options Holds additional flags set by the streams API.
77+
* @param string $opened_path If the path is opened successfully, and STREAM_USE_PATH is set.
78+
*
79+
* @return boolean Returns TRUE on success or FALSE on failure.
80+
*/
7081
public function stream_open($path, $mode, $options, &$opened_path)
7182
{
7283
$requestCallback = self::$requestCallback;
7384
$this->response = $requestCallback(new Request('GET', $path));
7485

75-
return (string) $this->response->getBody();
86+
return true;
7687
}
7788

89+
90+
/**
91+
* Read from stream.
92+
*
93+
* @link http://www.php.net/manual/en/streamwrapper.stream-read.php
94+
* @param int $count How many bytes of data from the current position should be returned.
95+
*
96+
* @return string If there are less than count bytes available, return as many as are available.
97+
* If no more data is available, return either FALSE or an empty string.
98+
*/
7899
public function stream_read($count)
79100
{
80101
$ret = substr($this->response->getBody(), $this->position, $count);
@@ -83,21 +104,56 @@ public function stream_read($count)
83104
return $ret;
84105
}
85106

107+
/**
108+
* Write to stream.
109+
*
110+
* @throws BadMethodCall If called, because this method is not applicable for this stream.
111+
* @link http://www.php.net/manual/en/streamwrapper.stream-write.php
112+
*
113+
* @param string $data Should be stored into the underlying stream.
114+
*
115+
* @return int
116+
*/
86117
public function stream_write($data)
87118
{
88119
throw new \BadMethodCall('No writing possible');
89120
}
90121

122+
/**
123+
* Retrieve the current position of a stream.
124+
*
125+
* This method is called in response to fseek() to determine the current position.
126+
*
127+
* @link http://www.php.net/manual/en/streamwrapper.stream-tell.php
128+
*
129+
* @return integer Should return the current position of the stream.
130+
*/
91131
public function stream_tell()
92132
{
93133
return $this->position;
94134
}
95135

136+
/**
137+
* Tests for end-of-file on a file pointer.
138+
*
139+
* @link http://www.php.net/manual/en/streamwrapper.stream-eof.php
140+
*
141+
* @return boolean Should return TRUE if the read/write position is at the end of the stream
142+
* and if no more data is available to be read, or FALSE otherwise.
143+
*/
96144
public function stream_eof()
97145
{
98146
return $this->position >= strlen($this->response->getBody());
99147
}
100148

149+
150+
/**
151+
* Retrieve information about a file resource.
152+
*
153+
* @link http://www.php.net/manual/en/streamwrapper.stream-stat.php
154+
*
155+
* @return array See stat().
156+
*/
101157
public function stream_stat()
102158
{
103159
return array();
@@ -141,11 +197,26 @@ public function stream_seek($offset, $whence)
141197
return false;
142198
}
143199

200+
/**
201+
* Change stream options.
202+
*
203+
* @link http://www.php.net/manual/en/streamwrapper.stream-metadata.php
204+
* @param string $path The file path or URL to set metadata.
205+
* @param integer $option One of the stream options.
206+
* @param mixed $var Value depending on the option.
207+
*
208+
* @return boolean Returns TRUE on success or FALSE on failure.
209+
*/
144210
public function stream_metadata($path, $option, $var)
145211
{
146212
return false;
147213
}
148214

215+
/**
216+
* Cleanup.
217+
*
218+
* @return void
219+
*/
149220
public function __destruct()
150221
{
151222
self::$requestCallback = null;

0 commit comments

Comments
 (0)