nozavroni / csvelte

🕺🏻 CSV and Tabular Data library for PHP
http://phpcsv.com/
Other
6 stars 0 forks source link

Add filter and other functionality to reader #55

Open deni-zen opened 8 years ago

deni-zen commented 8 years ago

Check out all these functions that can be applied to arrays using the underscore library:

http://brianhaveri.github.io/Underscore.php/

Take a look and see if you think it would be useful to implement any of those methods in the Reader class. I already included filter() in the documentation so add that at the very least. See the docs for how it's supposed to work.

This guy has some good ideas too...

http://csv.thephpleague.com/reading/

deni-zen commented 8 years ago

It might be useful to provide something like:

$reader = new CSVelte\Reader($fn, $flvr);
$reader->copy(new Flavor(array('delimiter' => "\t")));
deni-zen commented 8 years ago

Also, for the filter functionality I think I might prefer a syntax more like this:

<?php
$reader = CSVelte::reader('./files/data.csv', $flavor);
$reader->addFilter(function($row) {
    return (!empty($row['email']));
})->addFilter(function($row) {
    if ($row->doesSomeShit()) {
        return (count($row) == get_some_value($row));
    }
});
foreach ($reader as $line_no => $row) {
    // now only filtered rows will be iterated...
}
deni-zen commented 8 years ago

There are definitely methods I want to implement from Underscore but they'll have to wait for a later version. Pushing this to v0.2.

nozavroni commented 8 years ago

Pushing to v0.3