Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lpheller committed Oct 15, 2023
1 parent e2be619 commit ded95e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ so it can be accessed with `$row->starts_at`.
For custom class mapping the (normalized) column header has to match the class property name.

### Individually process row

The `get` method will allways return an of rows from the csv file. Either as arrays or object.
However, while being handy for smaller tasks, this is not memory efficient and can cause problems with large csv files.
To solve this, you can process each row individually and still let the package solve the mapping, filtering and skipping etc.
To solve this, you can process each row individually and still let the package solve the mapping, filtering and skipping etc.
This even makes handling large files with millions of records as simple as possible.

```php
Expand Down
10 changes: 5 additions & 5 deletions src/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ public function delimiter(string $delimiter)
* Map the CSV data to header keys.
* The header row will be used as the keys for the data rows.
*
* @param int $row The header row number
* @param int|array $headerRow The header row number or an array of header names
* @return $this
*/
public function mapToHeaders($row = 1)
public function mapToHeaders(array|int $headerRow = 1)
{
$this->mapToHeaderRow = true;

if (is_array($row)) {
if (is_array($headerRow)) {
$this->skipRows([]);
$this->headers = $row;
$this->headers = $headerRow;

return $this;
}

$this->setHeaderRow($row);
$this->setHeaderRow($headerRow);

// Skip the header row when processing the CSV
$this->skipRows([$this->headerRow]);
Expand Down

0 comments on commit ded95e7

Please sign in to comment.