Skip to content

Commit bfa3aa8

Browse files
committed
Improve documentation
1 parent efa1fc8 commit bfa3aa8

File tree

8 files changed

+61
-16
lines changed

8 files changed

+61
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All Notable changes to `Csv` will be documented in this file
44

5-
## Next - 2017-10-20
5+
## 9.1.0 - 2017-10-20
66

77
### Added
88

docs/9.0/connections/index.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,21 @@ try {
8181
}
8282
~~~
8383

84+
When using a non-seekable `SplFileObject`, a `RuntimeException` is thrown instead of a `League\Csv\Exception` when using features that requires a seekable CSV document. In the following example a seekable CSV document is required to update the inserted newline.
85+
86+
~~~php
87+
<?php
88+
89+
use League\Csv\Exception;
90+
use League\Csv\Writer;
91+
92+
try {
93+
$csv = Writer::createFromFileObject(new SplFileObject('php://output', 'w');
94+
$csv->setNewline("\r\n");
95+
$csv->insertOne(["foo", "bar"]);
96+
} catch (Exception | RuntimeException $e) {
97+
echo $e->getMessage(), PHP_EOL;
98+
}
99+
100+
//in order to change the CSV document newline a seekable CSV document is required
101+
~~~

docs/9.0/connections/instantiation.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Loading CSV documents
77

88
Because CSV documents come in different forms we use named constructors to offer several ways to load them.
99

10-
<p class="message-warning">Since version <code>9.1.0</code> non seekable CSV documents can be used but <code>Exception</code> will be thrown if features requiring seekable CSV document are used.</p>
10+
<p class="message-warning">Since version <code>9.1.0</code> non seekable CSV documents can be used but <strong>exceptions will be thrown if features requiring seekable CSV document are used.</strong></p>
1111

1212
## Loading from a string
1313

@@ -54,7 +54,13 @@ $reader = Reader::createFromPath('/path/to/your/csv/file.csv', 'r');
5454
$writer = Writer::createFromPath('/path/to/your/csv/file.csv', 'w');
5555
~~~
5656

57-
<p class="message-info"> The <code>$open_mode</code> default to <code>r+</code> if none is supplied.</p>
57+
<div class="message-notice">
58+
Starting with version <code>9.1.0</code>, <code>$open_mode</code> default to:
59+
<ul>
60+
<li><code>r+</code> for the <code>Writer</code> class</li>
61+
<li><code>r</code> for the <code>Reader</code> class</li>
62+
</ul>
63+
</div>
5864

5965
## Loading from a resource stream
6066

docs/9.0/connections/output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public AbstractCsv::getContent(void): string
2323
public AbstractCsv::__toString(void): string
2424
~~~
2525

26-
<p class="message-notice">The <code>getContent</code> method is added in version <code>9.1.0</code> and replaces the <code>__toString</code> method</p>
26+
<p class="message-notice">The <code>getContent</code> method is added in version <code>9.1.0</code> and replaces the <code>__toString</code> method which is <strong>deprecated</strong>.</p>
2727

2828
Use the `getContent` method to return the CSV full content.
2929

@@ -157,7 +157,7 @@ To avoid breaking the flow of your application, you should create a Response obj
157157
use League\Csv\Reader;
158158

159159
$reader = Reader::createFromPath('/path/to/my/file.csv', 'r');
160-
return new Response((string) $reader, 200, [
160+
return new Response($reader->getContent(), 200, [
161161
'Content-Encoding' => 'none',
162162
'Content-Type' => 'text/csv; charset=UTF-8',
163163
'Content-Disposition' => 'attachment; filename="name-for-your-file.csv"',

docs/9.0/interoperability/rfc4180-field.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ The `RFC4180Field` class enables to work around the following bugs in PHP's nati
2020
- [bug #43225](https://bugs.php.net/bug.php?id=43225): `fputcsv` incorrectly handles cells ending in `\` followed by `"`
2121
- [bug #55413](https://bugs.php.net/bug.php?id=55413): `str_getcsv` doesn't remove escape characters
2222
- [bug #74713](https://bugs.php.net/bug.php?id=74713): CSV cell split after `fputcsv()` + `fgetcsv()` round trip.
23-
- [bug #38301](https://bugs.php.net/bug.php?id=38301): field enclosure behavior in fputcsv (since version 9.1)
23+
- [bug #38301](https://bugs.php.net/bug.php?id=38301): field enclosure behavior in `fputcsv` (since version `9.1.0`)
2424

2525
When using this stream filter you can easily create or read a [RFC4180 compliant CSV document](https://tools.ietf.org/html/rfc4180#section-2) using `League\Csv` connections objects.
2626

2727

2828
<p class="message-warning">Changing the CSV objects control characters <strong>after registering the stream filter</strong> may result in unexpected returned records.</p>
2929

3030

31-
## Usage with CSV objects
31+
## Usage with League\CSV objects
3232

3333
~~~php
3434
<?php
@@ -48,14 +48,14 @@ The `RFC4180Field::addTo` method will register the stream filter if it is not al
4848
use League\Csv\RFC4180Field;
4949
use League\Csv\Writer;
5050

51-
$writer = Writer::createFromPath('php://temp');
51+
$writer = Writer::createFromPath('php://temp', 'r+');
5252
$writer->setNewline("\r\n"); //RFC4180 Line feed
5353
RFC4180Field::addTo($writer); //adding the stream filter to fix field formatting
5454
$writer->insertAll($iterable_data);
5555
$writer->output('mycsvfile.csv'); //outputting a RFC4180 compliant CSV Document
5656
~~~
5757

58-
<p class="message-notice">the <code>$whitespace_replace</code> argument is available since version 9.1</p>
58+
<p class="message-notice">the <code>$whitespace_replace</code> argument is available since version <code>9.1.0</code></p>
5959

6060
When the `$whitespace_replace` sequence is different from the empty space and does not contain:
6161

@@ -66,16 +66,27 @@ its value will be used to:
6666

6767
- To prevent `fputcsv` default behavior of always using enclosure when a whitespace is found in a record field
6868

69-
<p class="message-warning">The <code>$whitespace_replace</code> sequence should be a sequence not present in the inserted records, otherwise your CSV content will be affected by it.</p>
69+
~~~php
70+
<?php
71+
72+
use League\Csv\RFC4180Field;
73+
use League\Csv\Writer;
7074

75+
$writer = Writer::createFromPath('php://temp', 'r+');
76+
RFC4180Field::addTo($writer, "\0");
77+
$writer->insertOne(['foo bar', 'bar']);
78+
echo $writer->getContent(); //display 'foo bar,bar' instead of '"foo bar",bar'
79+
~~~
80+
81+
<p class="message-warning">The <code>$whitespace_replace</code> sequence should be a sequence not present in the inserted records, otherwise your CSV content will be affected by it.</p>
7182

7283
~~~php
7384
<?php
7485

7586
use League\Csv\RFC4180Field;
7687
use League\Csv\Writer;
7788

78-
$writer = Writer::createFromPath('php://temp');
89+
$writer = Writer::createFromPath('php://temp', 'r+');
7990
RFC4180Field::addTo($writer, 'fo'); // incorrect sequence this will alter your CSV
8091
$writer->insertOne(['foo bar', 'bar']);
8192
echo $writer->getContent(); //display ' o bar,baz' instead of foo bar,baz

docs/9.0/reader/index.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ class Reader extends AbstractCsv implements Countable, IteratorAggregate, JsonSe
2222

2323
The `League\Csv\Reader` class extends the general connections [capabilities](/9.0/connections/) to ease selecting and manipulating CSV document records.
2424

25-
<p class="message-warning">
26-
By default, the mode for a <code>Reader::createFromPath</code> is
27-
<code>r+</code> which looks for write permissions on the file and throws an <code>Exception</code> if
28-
the file cannot be opened with the permission set. For sake of clarity, it is
29-
strongly suggested to set <code>r</code> mode on the file to ensure it can be opened.</p>
25+
<p class="message-notice">Starting with version <code>9.1.0</code>, <code>createFromPath</code> when used from the <code>Reader</code> object will have its default set to <code>r</code>.</p>
26+
27+
<p class="message-notice">Prior to <code>9.1.0</code>, by default, the mode for a <code>Reader::createFromPath</code> is <code>r+</code> which looks for write permissions on the file and throws an <code>Exception</code> if the file cannot be opened with the permission set. For sake of clarity, it is strongly suggested to set <code>r</code> mode on the file to ensure it can be opened.</p>
3028

3129
## CSV example
3230

docs/9.0/writer/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ echo $writer->getContent(); // displays "one,two\r\n";
109109
~~~
110110

111111
<p class="message-info">The default newline sequence is <code>\n</code>;</p>
112+
<p class="message-warning">If you are using a non seekable CSV document, changing the newline character will trigger an exception.</p>
112113

113114
## Flushing the buffer
114115

docs/custom.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,15 @@ h4:hover .header-permalink,
5252
h5:hover .header-permalink {
5353
text-decoration: none;
5454
color:#777;
55+
}
56+
57+
main article div>code {
58+
display: inline-block;
59+
padding: 3px 5px;
60+
font-family: Consolas,Monaco,'Andale Mono',monospace;
61+
font-size: 17px;
62+
line-height: 100%;
63+
border-radius: 2px;
64+
background: #f5f6f7;
65+
border: solid #dcdddd 1px;
5566
}

0 commit comments

Comments
 (0)