Skip to content

Commit 2138a0e

Browse files
committed
Improve documentation
1 parent 26de738 commit 2138a0e

File tree

16 files changed

+484
-283
lines changed

16 files changed

+484
-283
lines changed

docs/9.0/connections/bom.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ title: BOM sequence detection and addition
55

66
# BOM sequences
77

8-
## Detecting the BOM sequence
8+
## Definition
99

1010
To improve interoperability with programs interacting with CSV, the package now provides an enum `Bom` to help you detect the appropriate <abbr title="Byte Order Mark">BOM</abbr> sequence.
1111

12-
### BOM definition
13-
1412
The `Bom` enum provides the following value :
1513

1614
- `Bom::Utf8` : which handles the `UTF-8` `BOM` sequence;
@@ -19,7 +17,9 @@ The `Bom` enum provides the following value :
1917
- `Bom::utf32Be` : which handles the `UTF-32` `BOM` with Big-Endian sequence;
2018
- `Bom::utf32Le` : which handles the `UTF-32` `BOM` with Little-Endian sequence;
2119

22-
### Detecting the BOM from a sequence of characters
20+
## Detection
21+
22+
### From a Sequence of Characters
2323

2424
```php
2525
Bom::fromSequence(mixed $sequence): Bom
@@ -37,7 +37,7 @@ Bom::tryFromSequence(Bom::Utf8->value.'hello world!'); //returns Bom::Utf8
3737
Bom::tryFromSequence('hello world!'.Bom::Utf16Le->value); //returns null
3838
```
3939

40-
### Detecting the BOM from the encoding name
40+
### From the Encoding Name
4141

4242
```php
4343
Bom::fromEncoding(string $encoding): Bom
@@ -55,7 +55,7 @@ Bom::tryFromEncoding('u_t_F--8'); //returns Bom::Utf8
5555
Bom::tryFromEncoding('foobar'); //returns null
5656
```
5757

58-
### Accessing the BOM properties
58+
## Accessing the BOM properties
5959

6060
Once you have a valid `Bom` instance you can access:
6161

@@ -99,7 +99,7 @@ bom_match(ByteSequence::BOM_UTF8.'hello world!'); //returns '\xEF\xBB\xBF'
9999
bom_match('hello world!'.ByteSequence::BOM_UTF16_BE); //returns ''
100100
```
101101

102-
## Managing CSV documents BOM sequence
102+
## Handling CSV documents
103103

104104
### Detecting the BOM sequence
105105

docs/9.0/connections/controls.md

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ title: Csv character controls
55

66
# CSV character controls
77

8-
To correctly parse a CSV document you are required to set the character controls to be used by the `Reader` or the `Writer` object.
8+
To correctly parse a CSV document, you are required to set the character controls to be used
9+
by the `Reader` or the `Writer` object.
910

1011
## The delimiter character
1112

12-
### Description
13-
14-
```php
15-
public AbstractCsv::setDelimiter(string $delimiter): self
16-
public AbstractCsv::getDelimiter(void): string
17-
```
18-
19-
### Example
13+
The `getDelimiter()` and `setDelimiter()` methods set and returns the CSV delimiter character
14+
used by the underlying class. The setter method expects a single byte character string to be used.
2015

2116
```php
2217
use League\Csv\Reader;
@@ -32,14 +27,8 @@ $delimiter = $csv->getDelimiter(); //returns ";"
3227

3328
## The enclosure character
3429

35-
### Description
36-
37-
```php
38-
public AbstractCsv::setEnclosure(string $enclosure): self
39-
public AbstractCsv::getEnclosure(void): string
40-
```
41-
42-
### Example
30+
The `getEnclosure()` and `setEnclosure()` methods set and returns the CSV enclosure character
31+
used by the underlying class. The setter method expects a single byte character string to be used.
4332

4433
```php
4534
use League\Csv\Writer;
@@ -55,22 +44,18 @@ $enclosure = $csv->getEnclosure(); //returns "|"
5544

5645
## The escape character
5746

58-
This is a PHP specific control character which sometimes interferes with CSV parsing and writing.
59-
It is recommended in versions preceding `9.2.0` to never change its default value unless you do understand its usage and its consequences.
47+
The `getEscape()` and `setEscape()` methods set and returns the CSV escape character
48+
used by the underlying class. The setter method expects a single byte character string to be used.
49+
50+
This is a PHP specific control character that sometimes interferes with CSV parsing and writing.
51+
It is recommended in versions preceding `9.2.0` to never change its default value unless you do
52+
understand its usage and its consequences.
6053

6154
<p class="message-warning">Starting with version <code>PHP7.4</code> it is recommended to use the library
6255
with the escape parameter equal to the empty string.
6356
see <a href="https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_proprietary_csv_escaping_mechanism">Deprecation for PHP8.4</a> and
6457
<a href="https://nyamsprod.com/blog/csv-and-php8-4/">CSV and PHP8.4</a> for more information.</p>
6558

66-
### Description
67-
68-
```php
69-
public AbstractCsv::setEscape(string $escape): self
70-
public AbstractCsv::getEscape(void): string
71-
```
72-
73-
### Example
7459

7560
```php
7661
use League\Csv\Reader;

docs/9.0/connections/instantiation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $writer = Writer::fromString('john,doe,[email protected]');
2727

2828
<p class="message-notice">The <code>$content</code> argument default value is an empty string to ease usage.</p>
2929

30-
## Loading from a file or a stream
30+
## Loading from a file pointer
3131

3232
<p class="message-notice">This new API is introduced in version <code>9.27.0</code></p>
3333

@@ -162,7 +162,7 @@ $reader = Reader::createFromFileObject(new SplFileObject('/path/to/your/csv/file
162162
$writer = Writer::createFromFileObject(new SplTempFileObject());
163163
```
164164

165-
## Accessing the CSV document path
165+
## Accessing the document path
166166

167167
<p class="message-notice">New in version <code>9.2.0</code></p>
168168

docs/9.0/converter/charset.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $records = $encoder->convert($csv);
4040

4141
The resulting data is converted from `iso-8859-15` to the default `UTF-8` since no output encoding charset was set using the `CharsertConverter::outputEncoding` method.
4242

43-
## CharsetConverter as a Writer formatter
43+
## As a Writer formatter
4444

4545
```php
4646
public CharsetConverter::__invoke(array $record): array
@@ -64,22 +64,22 @@ $writer->insertOne(["foo", "bébé", "jouet"]);
6464
//all 'utf-8' characters are now automatically encoded into 'iso-8859-15' charset
6565
```
6666

67-
## CharsetConverter as a PHP stream filter
67+
## As a PHP stream filter
6868

6969
```php
7070
public static CharsetConverter::addTo(AbstractCsv $csv, string $input_encoding, string $output_encoding): AbstractCsv
7171
public static CharsetConverter::register(): void
7272
public static CharsetConverter::getFiltername(string $input_encoding, string $output_encoding): string
7373
```
7474

75-
### Usage with CSV objects
75+
### With CSV object
7676

77-
If your CSV object supports PHP stream filters then you can use the `CharsetConverter` class as a PHP stream filter using the library [stream filtering mechanism](/9.0/connections/filters/) instead.
77+
If your CSV object supports PHP stream filters; then you can use the `CharsetConverter` class as a PHP stream filter using the library [stream filtering mechanism](/9.0/connections/filters/) instead.
7878

7979
The `CharsetConverter::addTo` static method:
8080

8181
- registers the `CharsetConverter` class under the generic filtername `convert.league.csv.*` if it is not registered yet;
82-
- configures the stream filter using the supplied parameters;
82+
- configure the stream filter using the supplied parameters;
8383
- adds the configured stream filter to the submitted CSV object;
8484

8585
```php
@@ -93,7 +93,7 @@ $writer->insertOne(["foo", "bébé", "jouet"]);
9393
//all 'utf-8' characters are now automatically encoded into 'iso-8859-15' charset
9494
```
9595

96-
### Usage with PHP stream resources
96+
### With PHP Stream
9797

9898
To use this stream filter outside `League\Csv` objects you need to:
9999

docs/9.0/converter/json.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ new JsonConverter()->download($record); //new and fast-forward method usage
3838

3939
Prior to converting your collection into a JSON structure, you may wish to configure it.
4040

41-
### JSON encode flags
41+
### Encoding Flags
4242

4343
```php
4444
public JsonConverter::addFlags(int ...$flag): self
@@ -97,7 +97,7 @@ $converter = (new JsonConverter())->withPrettyPrint(2);
9797

9898
will produce a JSON with an indentation size of `2`.
9999

100-
### Json encode depth
100+
### Encoding Depth
101101

102102
```php
103103
public JsonConverter::depth(int $depth): self
@@ -111,7 +111,7 @@ $converter = (new JsonConverter())->depth(2);
111111
$converter->depth; //returns the actual depth value (as used by json_encode)
112112
```
113113

114-
### Json encode indentation
114+
### Encode Indentation
115115

116116
<p class="message-warning">This method is deprecated as of version <code>9.19.0</code> use
117117
<code>JsonConverter::withPrettyPrint</code> instead and add the <code>$identSize</code> argument
@@ -131,7 +131,7 @@ size is the same as in PHP (ie : 4 characters long).
131131
$converter->indentSize; //returns the value used
132132
```
133133

134-
### Json encode formatter
134+
### Encoding Formatter
135135

136136
```php
137137
public JsonConverter::formatter(?callable $formatter): self
@@ -162,7 +162,7 @@ $converter = (new JsonConverter())->chunkSize(1_000);
162162
$converter->chunkSize; //returns the value used
163163
```
164164

165-
### JsonConverter::when
165+
### Conditional Settings
166166

167167
<p class="message-info">New feature introduced in version <code>9.22.0</code></p>
168168

docs/9.0/index.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ layout: default
1313

1414
**League\Csv** is a simple library to ease CSV document [loading](/9.0/connections/) as well as [writing](/9.0/writer/), [selecting](/9.0/reader/) and [converting](/9.0/converter/) CSV records.
1515

16-
## Usage
17-
18-
### Parsing a CSV document
16+
## Parsing a CSV document
1917

2018
Access and filter records from a CSV document saved on the local filesystem.
2119

@@ -39,7 +37,7 @@ foreach ($records as $record) {
3937
}
4038
```
4139

42-
### Exporting a database table as a CSV document
40+
## Exporting a database table as a CSV document
4341

4442
Fetch data using a `PDOStatement` object, then create a CSV document which is output to the browser.
4543

@@ -76,7 +74,7 @@ $csv->output('users.csv');
7674
die;
7775
```
7876

79-
### Importing CSV records into a database table
77+
## Importing CSV records into a database table
8078

8179
Import records from a CSV document into a database using a `PDOStatement` object
8280

@@ -104,7 +102,7 @@ foreach ($csv as $record) {
104102
}
105103
```
106104

107-
### Encoding a CSV document into a given charset
105+
## Encoding a CSV document into a given charset
108106

109107
It is not possible to detect the character encoding a CSV document (e.g. `UTF-8`, `UTF-16`, etc). However, it *is* possible to detect the input BOM and convert to UTF-8 where necessary.
110108

@@ -127,7 +125,7 @@ foreach ($csv as $record) {
127125
}
128126
```
129127

130-
### Converting a CSV document into a XML document
128+
## Converting a CSV document into a XML document
131129

132130
The `XMLConverter` object provided by this package can easily convert a CSV document into a `DOMDocument` object.
133131

docs/9.0/interoperability/enclose-field.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The `EncloseField` is a PHP stream filter which forces the `Writer` class to enc
1616
<code>Writer::forceEnclosure</code> method for better results and improved DX. Please refer to
1717
<a href="/9.0/writer/#force-enclosure">its documentation</a> for more informations.</p>
1818

19-
## Usage with Writer objects
19+
## With Writer objects
2020

2121
```php
2222
public static EncloseField::addTo(Writer $csv, string $sequence): Writer
@@ -40,7 +40,7 @@ $writer->output('mycsvfile.csv'); //outputting a CSV Document with all its field
4040

4141
<p class="message-warning">The <code>$sequence</code> argument should be a sequence containing at least one character that forces <code>fputcsv</code> to enclose the field value. If not, an <code>InvalidArgumentException</code> exception will be thrown.</p>
4242

43-
## Usage with PHP stream resources
43+
## With PHP Streams
4444

4545
```php
4646
public static EncloseField::register(): void

docs/9.0/interoperability/escape-formula-injection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $reader->first();
5757
// the escaping characters are removed.
5858
```
5959

60-
## Usage with PHP stream resources
60+
## Usage with PHP streams
6161

6262
You can use the `EscapeFormula` to format your records before calling `fputcsv` or `SplFileObject::fputcsv`.
6363

docs/9.0/interoperability/rfc4180-field.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ When using this stream filter you can easily create or read a [RFC4180 compliant
1818

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

21-
## Usage with League\CSV objects
21+
## With CSV objects
2222

2323
```php
2424
public static RFC4180Field::addTo(AbstractCsv $csv, string $whitespace_replace = ''): AbstractCsv
@@ -74,11 +74,11 @@ $writer->insertOne(['foo bar', 'bar']);
7474
echo $writer->getContent(); //display ' o bar,baz' instead of 'foo bar,baz'
7575
```
7676

77-
### On records insertion
77+
### On Records Insertion
7878

7979
<p class="message-info">To fully comply with <code>RFC4180</code> you will also need to use <code>League\Csv\Writer::setNewline</code>.</p>
8080

81-
### On records extraction
81+
### On Records Extraction
8282

8383
Conversely, to read a RFC4180 compliant CSV document, when using the `League\Csv\Reader` object, you just need to add the `League\Csv\RFC4180Field` stream filter as shown below:
8484

@@ -95,7 +95,7 @@ foreach ($csv as $record) {
9595
}
9696
```
9797

98-
## Usage with PHP stream resources
98+
## With PHP streams
9999

100100
```php
101101
public static RFC4180Field::register(): void

docs/9.0/reader/tabular-data-reader.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: Tabular Data Reader
55

66
# Tabular Data Reader Common API
77

8+
## Why does it exist?
9+
810
Introduced in version `9.6` the `League\Csv\TabularDataReader` interface provides a common
911
API to works with tabular data like structure. Once implemented, it can be used to work
1012
with HTML tables, simple RDBMS tables, CSV document and so forth. A tabular data
@@ -44,10 +46,10 @@ leaving your source data unchanged.
4446
## Available methods
4547

4648
While the `TabularDataReader` is not a fully fledged collection instance it still exposes a lots of methods
47-
that fall into the category of records collection manipulations. Because chaining is at the core of most of
48-
the methods you can be sure that each manipulation returns a new instance preserving your original data.
49+
that fall into the category of records collection manipulations. Because chaining is at the core of the API,
50+
most methods return a new instance preserving your original data.
4951

50-
### Countable, IteratorAggregate
52+
### Counting and traversing the records
5153

5254
Any `TabularDataReader` instance implements the `Countable` and the `IteratorAggregate` interface.
5355
It means that at any given time you can access the number of elements that are included in the instance

0 commit comments

Comments
 (0)