PHP code example of webit / doctrine-orm-query-builder-iterator

1. Go to this page and download the library: Download webit/doctrine-orm-query-builder-iterator 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/ */

    

webit / doctrine-orm-query-builder-iterator example snippets



use Webit\DoctrineORM\QueryBuilder\Iterator\QueryIterator;

/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */

$queryBuilder = $entityManager->getRepository('MyEntity')->createQueryBuilder();
$queryBuilder->orderBy('a.ble', 'DESC');

$iterator = new QueryIterator(
    $queryBuilder,
    20, // iterates in 50 elements batches (50 by default)
    ['MyEntity'], // clears entity manager before getting next batch (by default clears the whole entity manager) 
);

foreach ($iterator as $entity) {
    // do your stuff with the entity
}



use Webit\DoctrineORM\QueryBuilder\Iterator\IdsIterator;

/** @var \Doctrine\ORM\EntityManagerInterface $entityManager */

$queryBuilder = $entityManager->getRepository('MyEntity')->createQueryBuilder();
$queryBuilder->orderBy('a.ble', 'DESC');

$iterator = new IdsIterator(
    $queryBuilder,
    'a.id', // the ID field
    20, // iterates in 20 elements batches (50 by default)
    ['MyEntity'], // clears entity manager before getting next batch (by default clears the whole entity manager) 
);

foreach ($iterator as $entity) {
    // do your stuff with the entity
}