|
3 | 3 | namespace EbicsApi\Ebics\Contracts; |
4 | 4 |
|
5 | 5 | /** |
6 | | - * Buffer class interface. |
| 6 | + * Buffer interface. |
| 7 | + * |
| 8 | + * Provides a stream-based buffer for reading and writing data during |
| 9 | + * EBICS operations. This interface abstracts PHP stream operations |
| 10 | + * and is primarily used for handling large order data that may exceed |
| 11 | + * memory limits when processed as a single string. |
| 12 | + * |
| 13 | + * The buffer supports standard stream operations (open, close, read, write, |
| 14 | + * seek) as well as stream filter application for on-the-fly data |
| 15 | + * transformation (e.g., compression, encoding). |
| 16 | + * |
| 17 | + * EBICS Protocol Context: |
| 18 | + * Large order data (e.g., batch payment files) are often streamed rather |
| 19 | + * than loaded into memory. The buffer enables efficient handling of: |
| 20 | + * - Upload order data segmented into chunks |
| 21 | + * - Download order data reassembled from segments |
| 22 | + * - ZIP compression/decompression on the fly via stream filters |
7 | 23 | * |
8 | 24 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
9 | 25 | * @author Andrew Svirin |
10 | 26 | */ |
11 | 27 | interface BufferInterface |
12 | 28 | { |
| 29 | + /** |
| 30 | + * Default read length in bytes for buffer read operations. |
| 31 | + */ |
13 | 32 | const DEFAULT_READ_LENGTH = 1024; |
14 | 33 |
|
15 | 34 | /** |
16 | | - * Open buffer. |
| 35 | + * Open the buffer with the specified mode. |
| 36 | + * |
| 37 | + * Initializes the underlying stream resource for reading and/or writing. |
| 38 | + * Common modes: 'r' (read), 'w' (write), 'r+' (read/write). |
17 | 39 | * |
18 | | - * @param string $mode |
| 40 | + * @param string $mode Stream open mode (same as PHP fopen modes) |
19 | 41 | * |
20 | 42 | * @return void |
21 | 43 | */ |
22 | 44 | public function open(string $mode): void; |
23 | 45 |
|
24 | 46 | /** |
25 | | - * Close buffer. |
| 47 | + * Close the buffer and release the underlying stream resource. |
26 | 48 | * |
27 | 49 | * @return void |
28 | 50 | */ |
29 | 51 | public function close(): void; |
30 | 52 |
|
31 | 53 | /** |
32 | | - * Reset pointer. |
| 54 | + * Reset the stream pointer to the beginning of the buffer. |
33 | 55 | * |
34 | 56 | * @return void |
35 | 57 | */ |
36 | 58 | public function rewind(): void; |
37 | 59 |
|
38 | 60 | /** |
39 | | - * Write to buffer. |
| 61 | + * Write a string to the buffer at the current position. |
40 | 62 | * |
41 | | - * @param string $string |
| 63 | + * @param string $string The data to write |
42 | 64 | * |
43 | 65 | * @return void |
44 | 66 | */ |
45 | 67 | public function write(string $string): void; |
46 | 68 |
|
47 | 69 | /** |
48 | | - * Read from buffer. |
| 70 | + * Read data from the buffer at the current position. |
49 | 71 | * |
50 | | - * @param int|null $length |
| 72 | + * If no length is specified, reads up to DEFAULT_READ_LENGTH bytes. |
51 | 73 | * |
52 | | - * @return string |
| 74 | + * @param int|null $length Number of bytes to read (defaults to DEFAULT_READ_LENGTH) |
| 75 | + * |
| 76 | + * @return string The data read from the buffer |
53 | 77 | */ |
54 | 78 | public function read(?int $length = null): string; |
55 | 79 |
|
56 | 80 | /** |
57 | | - * Read from buffer full content. |
| 81 | + * Read the entire buffer content from the current position to EOF. |
58 | 82 | * |
59 | | - * @return string |
| 83 | + * @return string The full remaining content of the buffer |
60 | 84 | */ |
61 | 85 | public function readContent(): string; |
62 | 86 |
|
63 | 87 | /** |
64 | | - * Is end of file. |
| 88 | + * Check if the stream pointer has reached the end of the buffer. |
65 | 89 | * |
66 | | - * @return bool |
| 90 | + * @return bool True if the pointer is at EOF, false otherwise |
67 | 91 | */ |
68 | 92 | public function eof(): bool; |
69 | 93 |
|
70 | 94 | /** |
71 | | - * Move to pointer. |
| 95 | + * Move the stream pointer to the specified byte offset. |
72 | 96 | * |
73 | | - * @param int $offset |
| 97 | + * @param int $offset The byte offset to seek to |
74 | 98 | * |
75 | | - * @return int |
| 99 | + * @return int Returns 0 on success, or -1 on failure |
76 | 100 | */ |
77 | 101 | public function fseek(int $offset): int; |
78 | 102 |
|
79 | 103 | /** |
80 | | - * Apply filter. |
| 104 | + * Apply a stream filter to the buffer for data transformation. |
| 105 | + * |
| 106 | + * Filters can be used for on-the-fly compression (zlib), encoding |
| 107 | + * (convert.*), or custom data processing during read/write operations. |
81 | 108 | * |
82 | | - * @param string $filterName |
83 | | - * @param int $mode |
| 109 | + * @param string $filterName The PHP stream filter name (e.g., 'zlib.deflate') |
| 110 | + * @param int $mode Filter mode: STREAM_FILTER_READ, STREAM_FILTER_WRITE, or STREAM_FILTER_ALL |
84 | 111 | * |
85 | 112 | * @return void |
86 | 113 | */ |
87 | 114 | public function filterAppend(string $filterName, int $mode): void; |
88 | 115 |
|
89 | 116 | /** |
90 | | - * Length of content. |
| 117 | + * Get the total length of the buffer content in bytes. |
91 | 118 | * |
92 | | - * @return int |
| 119 | + * @return int The byte length of the buffer content |
93 | 120 | */ |
94 | 121 | public function length(): int; |
95 | 122 | } |
0 commit comments