Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Apr 28, 2017
1 parent bb0b574 commit 639820e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/9.0/connections/output.md
Expand Up @@ -9,7 +9,7 @@ Once your CSV document is loaded, you can print or enable downloading it using t

The methods output **are affected by** [the output BOM sequence](/9.0/connections/bom/) or the supplied [PHP stream filters](/9.0/connections/filters/).

<p class="message-info"><strong>Tip:</strong> Even though you can use the following methods with the <code>League\Csv\Writer</code> object. It is recommended to do so with the <code>League\Csv\Reader</code> class to avoid losing the file cursor position and getting unexpected results when inserting new data.</p>
<p class="message-info">Even though you can use the following methods with the <code>League\Csv\Writer</code> object. It is recommended to do so with the <code>League\Csv\Reader</code> class to avoid losing the file cursor position and getting unexpected results when inserting new data.</p>


## Printing the document
Expand Down Expand Up @@ -108,4 +108,4 @@ foreach ($reader->chunk(1024) as $chunk) {
echo "0\r\n\r\n";
~~~

<p class="message-info"><strong>Tip:</strong> To avoid breaking the flow of your framework based application, you should create a framework specific <code>Response</code> object when applicable using <code>AbstractCsv::__toString</code> or <code>AbstractCsv::chunk</code> depending on the size of your CSV document.</p>
<p class="message-info">To avoid breaking the flow of your framework based application, you should create a framework specific <code>Response</code> object when applicable using <code>AbstractCsv::__toString</code> or <code>AbstractCsv::chunk</code> depending on the size of your CSV document.</p>
4 changes: 2 additions & 2 deletions docs/9.0/converter/charset.md
Expand Up @@ -103,7 +103,7 @@ If your CSV object supports PHP stream filters then you can register the `Charse

The `CharsetConverter::registerStreamFilter` static method registers the `CharsetConverter` class under the following generic filtername `convert.league.csv.*`.

<p class="message-info"><strong>Tips:</strong> <code>CharsetConverter::registerStreamFilter</code> should be called once during your script execution time. The best place to call this method is in your bootstrap or configuration files script.</p>
<p class="message-info"><code>CharsetConverter::registerStreamFilter</code> should be called once during your script execution time. The best place to call this method is in your bootstrap or configuration files script.</p>

Once registered you can use the CSV object's `addStreamFilter` method to configure the stream filter by supplying the correct `$filtername` parameter.
For ease, you can use the `CharsetConverter::getFiltername` method.
Expand All @@ -127,4 +127,4 @@ $writer->insertOne(["foo", "bébé", "jouet"]);
//all 'utf-8' caracters are now automatically encoded into 'iso-8859-15' charset
~~~

<p class="message-info"><strong>Tips:</strong> If your system supports the <code>iconv</code> extension you should use PHP's built in iconv stream filters instead for better performance.</p>
<p class="message-info">If your system supports the <code>iconv</code> extension you should use PHP's built in iconv stream filters instead for better performance.</p>
16 changes: 10 additions & 6 deletions docs/9.0/converter/html.md
Expand Up @@ -34,10 +34,10 @@ Prior to converting your records collection into a HTML table, you may wish to c
public HTMLConverter::table(string $class_name, string $id_value = ''): self
~~~

This method sets:
This method sets the optional table `class` and `id` attribute values

- the optional table `class` attribute value, if none is uses it will default to `table-csv-data`;
- the optional table `id` attribute value;
<p class="message-info">The default <code>class</code> attribute value is <code>table-csv-data</code>.</p>
<p class="message-info">The default <code>id</code> attribute value is the empty string.</p>

### HTMLConverter::tr

Expand All @@ -46,7 +46,9 @@ This method sets:
public HTMLConverter::tr(string $record_offset_attribute_name): self
~~~

This method sets the optional attribute name for the record offset on the HTML `tr` tag. If none is use or an empty string is given, the record offset information won't be exported to the HTML table
This method sets the optional attribute name for the record offset on the HTML `tr` tag.

<p class="message-info">If none is use or an empty string is given, the record offset information won't be exported to the HTML table.</p>

### HTMLConverter::td

Expand All @@ -55,7 +57,9 @@ This method sets the optional attribute name for the record offset on the HTML `
public HTMLConverter::td(string $fieldname_attribute_name): self
~~~

This method sets the optional attribute name for the field name on the HTML `td` tag. If none is use or an empty string is given, the field name information won't be exported to the HTML table;
This method sets the optional attribute name for the field name on the HTML `td` tag.

<p class="message-info">If none is use or an empty string is given, the field name information won't be exported to the HTML table.</p>

## Conversion

Expand Down Expand Up @@ -103,4 +107,4 @@ echo $html;
// </table>
~~~

<p class="message-info"><strong>Tip:</strong> if needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>
<p class="message-info">If needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>
12 changes: 7 additions & 5 deletions docs/9.0/converter/json.md
Expand Up @@ -25,13 +25,15 @@ class JsonConverter
public JsonConverter::options(int $options): self
~~~

The `options` methods sets PHP's `json_encode` flag parameter. By default, the flag parameter is set to `0`.
The `options` methods sets PHP's `json_encode` flag parameter.

<p class="message-info">By default, the flag parameter is set to <code>0</code>.</p>

## Conversion

~~~php
<?php
public JsonConverter::convert(iterable $records, int $options = 0): string
public JsonConverter::convert(iterable $records): string
~~~

The `JsonConverter::convert` accepts:
Expand All @@ -41,9 +43,9 @@ The `JsonConverter::convert` accepts:

and returns a string.

<p class="message-warning">If a error occurs during the convertion an <code>RuntimeException</code> exception is thrown with additional information regarding the error.</p>
<p class="message-notice"><strong>Notice:</strong> To convert an iterator, <code>iterator_to_array</code> is used, which could lead to a performance penalty if you convert a large <code>Iterator</code>.</p>

<p class="message-warning"><strong>Warning:</strong> To convert an iterator, <code>iterator_to_array</code> is used, which could lead to a performance penalty if you convert a large <code>Iterator</code>.</p>
<p class="message-warning">If a error occurs during the convertion an <code>RuntimeException</code> exception is thrown with additional information regarding the error.</p>

~~~php
<?php
Expand Down Expand Up @@ -81,7 +83,7 @@ echo '<pre>', $json, PHP_EOL;
// ]
~~~

<p class="message-info"><strong>Tip:</strong> if needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>
<p class="message-info">If needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>

~~~php
<?php
Expand Down
16 changes: 10 additions & 6 deletions docs/9.0/converter/xml.md
Expand Up @@ -33,7 +33,9 @@ Prior to converting your records collection into XML, you may wish to configure
public XMLConverter::rootElement(string $node_name): self
~~~

This method sets the XML root name which defaults to `csv`.
This method sets the XML root name.

<p class="message-info">The default root element name is <code>csv</code>.</p>

### XMLConverter::recordElement

Expand All @@ -43,9 +45,10 @@ This method sets the XML root name which defaults to `csv`.
public XMLConverter::recordElement(string $node_name, string $record_offset_attribute_name = ''): self
~~~

This method sets the XML record name which defaults to `row`.
This method sets the XML record name and optionnally the attribute name for the record offset value if you want this information preserved.

Optionnally you can preserve the record offset by providing a name for its attribute on the XML record element using the `$record_offset_attribute_name` argument. If this argument is empty, the offset attribute information won't be added. By default, the attribute is not provided.
<p class="message-info">The default record element name is <code>row</code>.</p>
<p class="message-info">The default attribute name is the empty string.</p>

### XMLConverter::fieldElement

Expand All @@ -55,9 +58,10 @@ Optionnally you can preserve the record offset by providing a name for its attri
public XMLConverter::fieldElement(string $node_name, string $fieldname_attribute_name = ''): self
~~~

This method sets the XML field name which defaults to `cell`.
This method sets the XML field name and optionnally the attribute name for the field name value.

Optionnally you can preserve the field name by providing a name for its attribute on the XML field element using the `$fieldname_attribute_name` argument. If this argument is empty, the fieldname information won't be added. By default, the attribute is not provided.
<p class="message-info">The default field element name is <code>cell</code>.</p>
<p class="message-info">The default attribute name is the empty string.</p>

## Conversion

Expand Down Expand Up @@ -121,4 +125,4 @@ echo htmlentities($dom->saveXML());
// </csv>
~~~

<p class="message-info"><strong>Tip:</strong> if needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>
<p class="message-info">If needed you can use the <a href="/9.0/converter/charset/">CharsetConverter</a> object to correctly encode your CSV records before conversion.</p>
2 changes: 1 addition & 1 deletion docs/9.0/reader/index.md
Expand Up @@ -274,4 +274,4 @@ $records = $reader->select($stmt);
//$records is a League\Csv\ResultSet object
~~~

<p class="message-info"><strong>Tips:</strong> this method is equivalent of <a href="/9.0/reader/statement/#apply-the-constraints-to-a-csv-document">Statement::process</a>.</p>
<p class="message-info">This method is equivalent of <a href="/9.0/reader/statement/#apply-the-constraints-to-a-csv-document">Statement::process</a>.</p>
4 changes: 2 additions & 2 deletions docs/9.0/reader/statement.md
Expand Up @@ -22,7 +22,7 @@ The `League\Csv\Statement` class is a constraint builder to help ease selecting

When building a constraint, the methods do not need to be called in any particular order, and may be called multiple times. Because the `Statement` object is immutable, each time its constraint methods are called they will return a new `Statement` object without modifying the current `Statement` object.

<p class="message-info"><strong>Tips:</strong> Because the <code>Statement</code> object is independent of the <code>Reader</code> object it can be re-use on multiple <code>Reader</code> objects.</p>
<p class="message-info">Because the <code>Statement</code> object is independent of the <code>Reader</code> object it can be re-use on multiple <code>Reader</code> objects.</p>

## Filtering constraint

Expand Down Expand Up @@ -130,5 +130,5 @@ $stmt = (new Statement())
$records = $stmt->process($reader);
~~~

<p class="message-info"><strong>Tips:</strong> this method is equivalent of <a href="/9.0/reader/#selecting-csv-records">Reader::select</a>.</p>
<p class="message-info">This method is equivalent of <a href="/9.0/reader/#selecting-csv-records">Reader::select</a>.</p>

2 changes: 1 addition & 1 deletion docs/9.0/writer/index.md
Expand Up @@ -23,7 +23,7 @@ class Writer extends AbstractCsv

The `League\Csv\Writer` class extends the general connections [capabilities](/9.0/connections/) to create or update a CSV document.

<p class="message-info"><strong>Tips: </strong> When creating a file using the library, first insert all the data that need to be inserted before starting manipulating the CSV. If you manipulate your data before insertion, you may change the file cursor position and get unexpected results.</p>
<p class="message-info">When creating a file using the library, first insert all the data that need to be inserted before starting manipulating the CSV. If you manipulate your data before insertion, you may change the file cursor position and get unexpected results.</p>

## Inserting records

Expand Down

0 comments on commit 639820e

Please sign in to comment.