PHP code example of bakame / csv-doctrine-collection-bridge

1. Go to this page and download the library: Download bakame/csv-doctrine-collection-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bakame / csv-doctrine-collection-bridge example snippets




use Bakame\Csv\Extension as CsvExtension;
use Doctrine\Common\Collections\Criteria;
use League\Csv\Reader;

$csv = Reader::createFromPath('/path/to/my/file.csv');
$csv->setHeaderOffset(0);
$csv->setDelimiter(';');

$criteria = Criteria::create()
    ->andWhere(Criteria::expr()->eq('prenom', 'Adam'))
    ->orderBy( [ 'annee' => 'ASC', 'foo' => 'desc', ] )
    ->setFirstResult(0)
    ->setMaxResults(10)
;

//you can do

$resultset = CsvExtension\CriteriaConverter::convert($criteria)->process($csv);
$result = new CsvExtension\RecordCollection($resultset);

//or

$collection = new CsvExtension\RecordCollection($csv);
$result = $collection->matching($criteria);



use Bakame\Csv\Extension\RecordCollection;
use League\Csv\Reader;

$csv = Reader::createFromPath('/path/to/my/file.csv');
$csv->setHeaderOffset(0);
$csv->setDelimiter(';');

$collection = new RecordCollection($csv);



$csv = Reader::createFromPath('/path/to/my/file.csv');
$csv->setHeaderOffset(0);
$csv->setDelimiter(';');

$stmt = (new Statement())
    ->where(function (array $row) {
        return isset($row['email'])
            && false !== strpos($row['email'], '@github.com');
    });

$collection = new RecordCollection($stmt->process($csv));



use Bakame\Csv\Extension\CriteriaConverter;
use Doctrine\Common\Collections\Criteria;
use League\Csv\Reader;

$csv = Reader::createFromPath('/path/to/my/file.csv');
$csv->setHeaderOffset(0);
$csv->setDelimiter(';');

$criteria = Criteria::create()
    ->andWhere(Criteria::expr()->eq('name', 'Adam'))
    ->orderBy(['years', 'ASC'])
    ->setFirstResult(0)
    ->setMaxResults(10)
;

$stmt = CriteriaConverter::convert($criteria);
$resultset = $stmt->process($csv);



use Doctrine\Common\Collections\Criteria;
use League\Csv\Statement;

public static CriteriaConverter::convert(Criteria $criteria, Statement $stmt = null): Statement
public static CriteriaConverter::addWhere(Criteria $criteria, Statement $stmt = null): Statement
public static CriteriaConverter::addOrderBy(Criteria $criteria, Statement $stmt = null): Statement
public static CriteriaConverter::addInterval(Criteria $criteria, Statement $stmt = null): Statement