Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing the Buffer instance #554

Merged
merged 4 commits into from
Feb 19, 2025
Merged

Introducing the Buffer instance #554

merged 4 commits into from
Feb 19, 2025

Conversation

nyamsprod
Copy link
Member

@nyamsprod nyamsprod commented Feb 18, 2025

The League\Csv\Buffer class enables doing the following:

use League\Csv\Buffer;
use League\Csv\Query\Constraint\Column;
use League\Csv\Reader;
use League\Csv\Writer;

$csv = <<<CSV
rating,title,author,type,asin,tags,review
...
...
CSV;

$document = Reader::createFromString($csv);
$document->setHeaderOffset(0);

$buffer = Buffer::from($document->slice(0, 50));
$buffer->delete(Column::filterOn('rating', '=', ''));
$buffer->update(Column::filterOn('tags', '=', ''), ['tags' => 'book sci-fi']);
$buffer->insertOne([
    'rating' => 3,
    'author' => 'Echiro Oda',
    'title' => 'One Piece',
    'type' => 'Manga',
    'asin' => '000254123',
    'tags' => 'book manga sci-fi shonen  fights pirates',
    'review' => 'still need to read at least 1100 chapters before making my mind.',
]);

$newDocument = Writer::createFromString();
$newDocument->setDelimiter(";");
$newDocument->forceEnclosure();
$buffer->to($newDocument);

echo $newDocument->toString(), PHP_EOL;

//display

rating,title,author,type,asin,tags,review
...
...
"3";"One Piece";"Echiro Oda";"Manga";"000254123";"book manga sci-fi shonen  fights pirates";"still need to read at least 1100 chapters before making my mind."

@nyamsprod nyamsprod merged commit f175cea into master Feb 19, 2025
19 checks passed
@nyamsprod nyamsprod deleted the feature/add-buffer-class branch February 19, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant