Skip to content

Commit f175cea

Browse files
authored
Introducing the Buffer instance (#554)
Introducing the Buffer instance
1 parent 456850b commit f175cea

26 files changed

+1954
-593
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All Notable changes to `Csv` will be documented in this file
1212
- `ResultSet::from` and `ResultSet::tryFrom`
1313
- `RdbmsResult` class to allow converting RDBMS result into `ResultSet`
1414
- `TabularData` interface
15+
- `Buffer` class
1516
- `XMLConverter::supportsHeader`
1617
- `XMLConverter::when`
1718
- `HTMLConverter::when`

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
"require-dev": {
3333
"ext-dom": "*",
3434
"ext-xdebug": "*",
35-
"friendsofphp/php-cs-fixer": "^3.68.1",
36-
"phpbench/phpbench": "^1.3.1",
37-
"phpstan/phpstan": "^1.12.15",
35+
"friendsofphp/php-cs-fixer": "^3.69.0",
36+
"phpbench/phpbench": "^1.4.0",
37+
"phpstan/phpstan": "^1.12.18",
3838
"phpstan/phpstan-deprecation-rules": "^1.2.1",
3939
"phpstan/phpstan-phpunit": "^1.4.2",
40-
"phpstan/phpstan-strict-rules": "^1.6.1",
41-
"phpunit/phpunit": "^10.5.16 || ^11.5.3",
42-
"symfony/var-dumper": "^6.4.8 || ^7.2.0"
40+
"phpstan/phpstan-strict-rules": "^1.6.2",
41+
"phpunit/phpunit": "^10.5.16 || ^11.5.7",
42+
"symfony/var-dumper": "^6.4.8 || ^7.2.3"
4343
},
4444
"autoload": {
4545
"psr-4": {
46-
"League\\Csv\\": "src/"
46+
"League\\Csv\\": "src"
4747
},
4848
"files": ["src/functions_include.php"]
4949
},

docs/9.0/converter/xml.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,49 @@ echo htmlentities($dom->saveXML());
186186
// </root>
187187
```
188188

189+
The result is different if you set the field element as `null`:
190+
191+
```php
192+
$converter = new XMLConverter()
193+
->rootElement('csv')
194+
->recordElement('record', 'offset')
195+
->fieldElement(null)
196+
;
197+
198+
$records = $stmt->process($csv);
199+
200+
$dom = new DOMDocument('1.0');
201+
$dom->loadXML('<root><header><name>My CSV Document</name></header></root>');
202+
203+
$data = $converter->import($records, $dom);
204+
$dom->appendChild($data);
205+
$dom->formatOutput = true;
206+
$dom->encoding = 'iso-8859-15';
207+
208+
echo '<pre>', PHP_EOL;
209+
echo htmlentities($dom->saveXML());
210+
// <?xml version="1.0" encoding="iso-8859-15"?>
211+
// <root>
212+
// <header>
213+
// <name>My CSV Document</name>
214+
// </header>
215+
// <csv>
216+
// <record offset="71">
217+
// <prenoms>Anaïs</field>
218+
// <nombre>137</field>
219+
// <sexe>F</field>
220+
// <annee>2004</field>
221+
// </record>
222+
// <record offset="1099">
223+
// <prenoms>Anaïs</field>
224+
// <nombre>124</field>
225+
// <sexe>F</field>
226+
// <annee>2005</field>
227+
// </record>
228+
// </csv>
229+
// </root>
230+
```
231+
189232
## Conversion
190233

191234
<p class="message-notice">The method is deprecated in version <code>9.22.0</code> use <code>XMLConverter::import</code> instead</p>

docs/9.0/interoperability/tabular-data-importer.md

Lines changed: 0 additions & 142 deletions
This file was deleted.

docs/9.0/reader/resultset.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ The `createFromTabularData` supports the following Database Extensions:
4444
As such using the instance on huge results will trigger high memory usage as all the data will be stored in a
4545
<code>ArrayIterator</code> instance for cache to allow rewinding and inspecting the tabular data.</p>
4646

47-
Please refer to the [TabularData Importer](/9.0/interoperability/tabular-data-importer) for more information.
48-
4947
## Selecting records
5048

5149
Please header over the [TabularDataReader documentation page](/9.0/reader/tabular-data-reader)

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@ $exists = $resultSet->exists(fn (array $records) => in_array('twenty-five', $rec
237237

238238
## Selecting columns
239239

240+
### fetchColumn
241+
242+
The `fetchColumn` returns an Iterator containing all the values of a single column specified by its
243+
header offset if you provide an integer or its header name if you provide a string name that exists.
244+
245+
```php
246+
$reader = Reader::createFromPath('/path/to/my/file.csv');
247+
$reader->setHeaderOffset(0);
248+
$records = (new Statement())->process($reader);
249+
foreach ($records->fetchColumn(3) as $value) {
250+
//$value is a string representing the value
251+
//of a given record for the selected column
252+
//$value may be equal to 'john.doe@example.com'
253+
}
254+
255+
foreach ($records->fetchColumn('3') as $value) {
256+
//$value is a string representing the value
257+
//of a given record for the selected column whose name is '3'
258+
//$value may be equal to 'john.doe@example.com'
259+
}
260+
```
261+
262+
Two additional methods are added to ease distinguish usage
263+
240264
### fetchColumnByName
241265

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

0 commit comments

Comments
 (0)