Skip to content

Commit

Permalink
Introducing the Buffer instance (#554)
Browse files Browse the repository at this point in the history
Introducing the Buffer instance
  • Loading branch information
nyamsprod authored Feb 19, 2025
1 parent 456850b commit f175cea
Show file tree
Hide file tree
Showing 26 changed files with 1,954 additions and 593 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All Notable changes to `Csv` will be documented in this file
- `ResultSet::from` and `ResultSet::tryFrom`
- `RdbmsResult` class to allow converting RDBMS result into `ResultSet`
- `TabularData` interface
- `Buffer` class
- `XMLConverter::supportsHeader`
- `XMLConverter::when`
- `HTMLConverter::when`
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
"require-dev": {
"ext-dom": "*",
"ext-xdebug": "*",
"friendsofphp/php-cs-fixer": "^3.68.1",
"phpbench/phpbench": "^1.3.1",
"phpstan/phpstan": "^1.12.15",
"friendsofphp/php-cs-fixer": "^3.69.0",
"phpbench/phpbench": "^1.4.0",
"phpstan/phpstan": "^1.12.18",
"phpstan/phpstan-deprecation-rules": "^1.2.1",
"phpstan/phpstan-phpunit": "^1.4.2",
"phpstan/phpstan-strict-rules": "^1.6.1",
"phpunit/phpunit": "^10.5.16 || ^11.5.3",
"symfony/var-dumper": "^6.4.8 || ^7.2.0"
"phpstan/phpstan-strict-rules": "^1.6.2",
"phpunit/phpunit": "^10.5.16 || ^11.5.7",
"symfony/var-dumper": "^6.4.8 || ^7.2.3"
},
"autoload": {
"psr-4": {
"League\\Csv\\": "src/"
"League\\Csv\\": "src"
},
"files": ["src/functions_include.php"]
},
Expand Down
43 changes: 43 additions & 0 deletions docs/9.0/converter/xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,49 @@ echo htmlentities($dom->saveXML());
// </root>
```

The result is different if you set the field element as `null`:

```php
$converter = new XMLConverter()
->rootElement('csv')
->recordElement('record', 'offset')
->fieldElement(null)
;

$records = $stmt->process($csv);

$dom = new DOMDocument('1.0');
$dom->loadXML('<root><header><name>My CSV Document</name></header></root>');

$data = $converter->import($records, $dom);
$dom->appendChild($data);
$dom->formatOutput = true;
$dom->encoding = 'iso-8859-15';

echo '<pre>', PHP_EOL;
echo htmlentities($dom->saveXML());
// <?xml version="1.0" encoding="iso-8859-15"?>
// <root>
// <header>
// <name>My CSV Document</name>
// </header>
// <csv>
// <record offset="71">
// <prenoms>Anaïs</field>
// <nombre>137</field>
// <sexe>F</field>
// <annee>2004</field>
// </record>
// <record offset="1099">
// <prenoms>Anaïs</field>
// <nombre>124</field>
// <sexe>F</field>
// <annee>2005</field>
// </record>
// </csv>
// </root>
```

## Conversion

<p class="message-notice">The method is deprecated in version <code>9.22.0</code> use <code>XMLConverter::import</code> instead</p>
Expand Down
142 changes: 0 additions & 142 deletions docs/9.0/interoperability/tabular-data-importer.md

This file was deleted.

2 changes: 0 additions & 2 deletions docs/9.0/reader/resultset.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ The `createFromTabularData` supports the following Database Extensions:
As such using the instance on huge results will trigger high memory usage as all the data will be stored in a
<code>ArrayIterator</code> instance for cache to allow rewinding and inspecting the tabular data.</p>

Please refer to the [TabularData Importer](/9.0/interoperability/tabular-data-importer) for more information.

## Selecting records

Please header over the [TabularDataReader documentation page](/9.0/reader/tabular-data-reader)
Expand Down
24 changes: 24 additions & 0 deletions docs/9.0/reader/tabular-data-reader.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ $exists = $resultSet->exists(fn (array $records) => in_array('twenty-five', $rec

## Selecting columns

### fetchColumn

The `fetchColumn` returns an Iterator containing all the values of a single column specified by its
header offset if you provide an integer or its header name if you provide a string name that exists.

```php
$reader = Reader::createFromPath('/path/to/my/file.csv');
$reader->setHeaderOffset(0);
$records = (new Statement())->process($reader);
foreach ($records->fetchColumn(3) as $value) {
//$value is a string representing the value
//of a given record for the selected column
//$value may be equal to '[email protected]'
}

foreach ($records->fetchColumn('3') as $value) {
//$value is a string representing the value
//of a given record for the selected column whose name is '3'
//$value may be equal to '[email protected]'
}
```

Two additional methods are added to ease distinguish usage

### fetchColumnByName

The `fetchColumnByName` returns an Iterator containing all the values of a single column specified by its header name if it exists.
Expand Down
Loading

0 comments on commit f175cea

Please sign in to comment.