1 | <?php |
||
44 | class StreamBuffer implements FileBufferInterface |
||
45 | { |
||
46 | /** |
||
47 | * The file resource |
||
48 | * |
||
49 | * @var resource |
||
50 | */ |
||
51 | protected $stream; |
||
52 | |||
53 | /** |
||
54 | * Creates a new file buffer with the given path |
||
55 | * |
||
56 | * @param string $path The path |
||
57 | * @param string $mode The file mode |
||
58 | * @throws StreamBufferException If the stream cannot be opened in the given mode |
||
59 | */ |
||
60 | 55 | public function __construct($path, $mode = 'r+') |
|
67 | |||
68 | /** |
||
69 | * Destructor closes file stream handle |
||
70 | */ |
||
71 | 53 | public function __destruct() |
|
75 | |||
76 | /** |
||
77 | * Returns the complete contents of the buffer |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | 5 | public function getBuffer() |
|
89 | |||
90 | /** |
||
91 | * Returns true if the pointer is at the end of the buffer |
||
92 | * |
||
93 | * @return boolean |
||
94 | */ |
||
95 | 26 | public function isEof() |
|
99 | |||
100 | /** |
||
101 | * Reads $count bytes from the buffer |
||
102 | * |
||
103 | * @param integer $count The number of bytes to read |
||
104 | * @return string|null |
||
105 | */ |
||
106 | 28 | public function read($count) |
|
110 | |||
111 | /** |
||
112 | * Writes the given date into the buffer at the current pointer position |
||
113 | * |
||
114 | * @param string $data The data to write |
||
115 | * @return integer The number of bytes written |
||
116 | */ |
||
117 | 27 | public function write($data) |
|
121 | |||
122 | /** |
||
123 | * Returns the current pointer position |
||
124 | * |
||
125 | * @return integer |
||
126 | */ |
||
127 | 20 | public function getPosition() |
|
131 | |||
132 | /** |
||
133 | * Sets the pointer position |
||
134 | * |
||
135 | * @param integer $position The position in bytes |
||
136 | * @param integer $whence The reference from where to measure $position (SEEK_SET, SEEK_CUR or SEEK_END) |
||
137 | * @return boolean True if the position could be set |
||
138 | */ |
||
139 | 19 | public function setPosition($position, $whence) |
|
143 | |||
144 | /** |
||
145 | * Returns the stat information for the buffer |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | 17 | public function getStat() |
|
153 | |||
154 | /** |
||
155 | * Flushes the buffer to the storage media |
||
156 | * |
||
157 | * @return boolean |
||
158 | */ |
||
159 | 22 | public function flush() |
|
163 | |||
164 | /** |
||
165 | * Closes the buffer |
||
166 | */ |
||
167 | 53 | public function close() |
|
174 | } |
||
175 |