8000 Adding explaining Docblocks · Rakdar/reactphp-csv@c438430 · GitHub
[go: up one dir, main page]

Skip to content

Commit c438430

Browse files
committed
Adding explaining Docblocks
1 parent f882e93 commit c438430

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

src/Reader.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use React\Stream\ReadableStreamInterface;
88
use React\Stream\Util;
99

10+
/**
11+
* Object to parse a csv-stream into its separate elements
12+
*
13+
* @package Rakdar\React\Csv
14+
*/
1015
class Reader implements EventEmitterInterface
1116
{
1217
use EventEmitterTrait;
@@ -46,12 +51,23 @@ public function __construct(ReadableStreamInterface $stream)
4651
Util::forwardEvents($this->stream, $this, ["end", "error", "close"]);
4752
}
4853

54+
/**
55+
* Handles the data emitted from the receiving stream.
56+
*
57+
* @param $data
58+
* @return void
59+
*/
4960
public function handleData($data)
5061
{
5162
fputs($this->buffer, $data);
5263
$this->parseBuffer();
5364
}
5465

66+
/**
67+
* Tries to parse the buffer and emits header- or data-events.
68+
*
69+
* @return void
70+
*/
5571
public function parseBuffer()
5672
{
5773
rewind($this->buffer);
@@ -86,22 +102,43 @@ public function parseBuffer()
86102
fputs($this->buffer, $dataRemainig);
87103
}
88104

105+
/**
106+
* Defines if the first row shold be handled separately as header.
107+
*
108+
* @param $parseHeader bool
109+
* @return void
110+
*/
89111
public function setParseHeader($parseHeader)
90112
{
91113
$this->parseHeader = (bool)$parseHeader;
92114
}
93115

116+
/**
117+
* Checks if parsing is paused.
118+
*
119+
* @return bool
120+
*/
94121
public function isPaused()
95122
{
96123
return $this->paused;
97124
}
98125

126+
/**
127+
* Pauses the underlying stream and pauses emitting data-events.
128+
*
129+
* @return void
130+
*/
99131
public function pause()
100132
{
101133
$this->stream->pause();
102134
$this->paused = true;
103135
}
104136

137+
/**
138+
* Resumes the underlying stream and starts parsing the buffer.
139+
*
140+
* @return void
141+
*/
105142
public function resume()
106143
{
107144
$this->paused = false;
@@ -114,33 +151,63 @@ 8000 public function resume()
114151
}
115152
}
116153

154+
/**
155+
* Stops emitting events and closes the underlying stream.
156+
*
157+
* @return void
158+
*/
117159
public function close()
118160
{
119161
rewind($this->buffer);
120162
ftruncate($this->buffer, 0);
121163
$this->stream->close();
122164
}
123165

166+
/**
167+
* Returns the header-field in case {@see setParseHeader} is set to true.
168+
*
169+
* @return array|null
170+
*/
124171
public function getHeader()
125172
{
126173
return $this->header;
127174
}
128175

176+
/**
177+
* Returns the number of rows parsed, including the optional header-row.
178+
*
179+
* @return int
180+
*/
129181
public function getRowsParsed()
130182
{
131183
return $this->rowsParsed;
132184
}
133185

186+
/**
187+
* Sets the delimiter character.
188+
*
189+
* @param $delimiter string
190+
*/
134191
public function setDelimiter($delimiter)
135192
{
136193
$this->delimiter = mb_substr($delimiter, 0, 1);
137194
}
138195

196+
/**
197+
* Sets the enclosure character.
198+
*
199+
* @param $enclosure string
200+
*/
139201
public function setEnclosure($enclosure)
140202
{
141203
$this->enclosure = mb_substr($enclosure, 0, 1);
142204
}
143205

206+
/**
207+
* Sets the escape character.
208+
*
209+
* @param $escape string
210+
*/
144211
public function setEscape($escape)
145212
{
146213
$this->escape = mb_substr($escape, 0, 1);

src/Writer.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
use React\Stream\Util;
88
use React\Stream\WritableStreamInterface;
99

10+
/**
11+
* Object to write csv-data to {@see WritableStreamInterface}.
12+
*
13+
* @package Rakdar\React\Csv
14+
*/
1015
class Writer implements EventEmitterInterface
1116
{
1217
use EventEmitterTrait;
@@ -18,7 +23,10 @@ class Writer implements EventEmitterInterface
1823
protected $enclosure = "\"";
1924
protected $escape = "\\";
2025

21-
26+
/**
27+
* Writer constructor.
28+
* @param WritableStreamInterface $stream
29+
*/
2230
public function __construct(WritableStreamInterface $stream)
2331
{
2432
$this->stream = $stream;
@@ -28,6 +36,12 @@ public function __construct(WritableStreamInterface $stream)
2836
Util::forwardEvents($this->stream, $this, ["drain", "error", "close"]);
2937
}
3038

39+
/**
40+
* Writes csv-conform string to underlying stream.
41+
*
42+
* @param array $data
43+
* @return void
44+
*/
3145
public function write(array $data)
3246
{
3347
// Resetting the internal buffer
@@ -46,21 +60,41 @@ public function write(array $data)
4660
$this->stream->write(stream_get_contents($this->buffer));
4761
}
4862

63+
/**
64+
* Closes the underlying stream.
65+
*
66+
* @return void
67+
*/
4968
public function close()
5069
{
5170
$this->stream->close();
5271
}
5372

73+
/**
74+
* Sets the delimiter character.
75+
*
76+
* @param $delimiter string
77+
*/
5478
public function setDelimiter($delimiter)
5579
{
5680
$this->delimiter = mb_substr($delimiter, 0, 1);
5781
}
5882

83+
/**
84+
* Sets the enclosure character.
85+
*
86+
* @param $enclosure string
87+
*/
5988
public function setEnclosure($enclosure)
6089
{
6190
$this->enclosure = mb_substr($enclosure, 0, 1);
6291
}
6392

93+
/**
94+
* Sets the escape character.
95+
*
96+
* @param $escape string
97+
*/
6498
public function setEscape($escape)
6599
{
66100
$this->escape = mb_substr($escape, 0, 1);

0 commit comments

Comments
 (0)
0