PHPackages                             ang3/doctrine-orm-batch-process - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ang3/doctrine-orm-batch-process

ActiveLibrary[Database &amp; ORM](/categories/database)

ang3/doctrine-orm-batch-process
===============================

Doctrine ORM Batch component

v1.0.0(3y ago)0879MITPHPPHP &gt;=8.1

Since Jun 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Ang3/doctrine-orm-batch-process)[ Packagist](https://packagist.org/packages/ang3/doctrine-orm-batch-process)[ Docs](https://github.com/Ang3/doctrine-orm-batch-process)[ RSS](/packages/ang3-doctrine-orm-batch-process/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Doctrine ORM Batch Component
============================

[](#doctrine-orm-batch-component)

[![Code Quality](https://github.com/Ang3/doctrine-orm-batch-process/actions/workflows/php_lint.yml/badge.svg)](https://github.com/Ang3/doctrine-orm-batch-process/actions/workflows/php_lint.yml)[![PHPUnit Tests](https://github.com/Ang3/doctrine-orm-batch-process/actions/workflows/phpunit.yml/badge.svg)](https://github.com/Ang3/doctrine-orm-batch-process/actions/workflows/phpunit.yml)[![Latest Stable Version](https://camo.githubusercontent.com/b088613072b9583accc0802f2447a545a435bfd3abf72189fa402cbfb9cd74ea/68747470733a2f2f706f7365722e707567782e6f72672f616e67332f646f637472696e652d6f726d2d62617463682d70726f636573732f762f737461626c65)](https://packagist.org/packages/ang3/doctrine-orm-batch-process)[![Latest Unstable Version](https://camo.githubusercontent.com/47c3c89e6aa2cd2ec927072ee541efb1ad32e35e031dc84f2547e6e1c93e8de3/68747470733a2f2f706f7365722e707567782e6f72672f616e67332f646f637472696e652d6f726d2d62617463682d70726f636573732f762f756e737461626c65)](https://packagist.org/packages/ang3/doctrine-orm-batch-process)[![Total Downloads](https://camo.githubusercontent.com/a5650683b5ca7d4c6582300692b0ddb5c8b9e1e4b71014bbf42d971f4866ccd8/68747470733a2f2f706f7365722e707567782e6f72672f616e67332f646f637472696e652d6f726d2d62617463682d70726f636573732f646f776e6c6f616473)](https://packagist.org/packages/ang3/doctrine-orm-batch-process)

This component helps you to deal with [batch-processing](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/batch-processing.html)in the context of Doctrine ORM transactions.

> The main problem with bulk operations is usually not to run out of memory and this is especially what the strategies presented here provide help with. -- *Doctrine ORM documentation*

The batch process component allows you to build bulk operations very easily with some advanced features.

Installation
------------

[](#installation)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require ang3/doctrine-orm-batch-process
```

This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Usage
-----

[](#usage)

A batch process is a basic **loop** using an **iterator** to do some logic with a **handler**. The iterator is mandatory and the handler is optional.

In all cases, the entity manager is flushed and cleared when the buffer size is reached (by default: 20).

Create a process
----------------

[](#create-a-process)

To create a process, use the constructor with the entity manager and an iterator, or use one of defined static shortcut methods as to your needs:

```
use Ang3\Doctrine\ORM\Batch\BatchProcess;

$myProcess = new BatchProcess($entityManager, $myIterator, $myHandler = null, $bufferSize = 20);

// For chaining calls
$myProcess = BatchProcess::create($entityManager, $myIterator);

/*
 * SHORTCUT METHODS FOR BUILT-IN ITERATORS
 */

// Iterate from identified entities
$myProcess = BatchProcess::iterateEntities($entityManager, $entityFqcn, array $identifiers);

// Iterate from an ORM query or query builder instance
$myProcess = BatchProcess::iterateQueryResult($query);

// Iterate from iterable or callable
$myProcess = BatchProcess::iterateData($entityManager, iterable|\Closure $data);
```

To execute the process:

```
$nbIterations = $myProcess->execute();
```

Advanced options
----------------

[](#advanced-options)

This component provides some useful advanced options.

### Handlers

[](#handlers)

A handler is a class implementing the interface `Ang3\Doctrine\ORM\Batch\Handler\BatchHandlerInterface`. This class is called on each iteration. It allows you to persist/remove entities, or whatever you need with custom handlers.

This interface describes the method called by the batch process: `__invoke(\Ang3\Doctrine\ORM\Batch\BatchIteration $iteration)`.

The component provides some useful built-in handlers.

#### Persist entity handler

[](#persist-entity-handler)

This handler persists entities into database.

```
use Ang3\Doctrine\ORM\Batch\Handler\PersistEntityHandler;

$myHandler = PersistEntityHandler::new()
    // Handler options...
    ->skipInsertions() // Ignore new entities (without ID)
    ->skipUpdates() // Ignore stored entities (with ID)
    ->onPrePersist($myCallable) // This callable is called BEFORE each persist.
    ->onPostPersist($myCallable) // This callable is called AFTER each persist.
;
```

Callable arguments:

1. `object` The entity
2. `Ang3\Doctrine\ORM\Batch\BatchIteration` The iteration.

#### Remove entity handler

[](#remove-entity-handler)

This handler removes entities into database.

```
use Ang3\Doctrine\ORM\Batch\Handler\RemoveEntityHandler;

$myHandler = RemoveEntityHandler::new()
    // Handler options...
    ->onPreRemove($myCallable) // This callable is called BEFORE each removing.
    ->onPostRemove($myCallable) // This callable is called AFTER each removing.
;
```

Callable arguments:

1. `object` The entity
2. `Ang3\Doctrine\ORM\Batch\BatchIteration` The iteration.

#### Callable handler

[](#callable-handler)

This handler holds a simple callable.

```
use Ang3\Doctrine\ORM\Batch\Handler\CallableHandler;

$myHandler = CallableHandler::new($myCallable);
```

Callable arguments:

1. `mixed` Iterator data
2. `Ang3\Doctrine\ORM\Batch\BatchIteration` The iteration.

#### Chain handler

[](#chain-handler)

This handler allows you to chain handlers in a specific order.

```
use Ang3\Doctrine\ORM\Batch\Handler\ChainHandler;

$myHandler = ChainHandler::new()
    // Handler options...
    ->append($myHandler1) // Add a handler at the end of the chain
    ->prepend($myHandler2) // Add a handler at the beginning of the chain
    ->clear() // Remove all handlers from the chain
;
```

#### Custom handler

[](#custom-handler)

Create a class implementing the interface `Ang3\Doctrine\ORM\Batch\Handler\BatchHandlerInterface`.

```
namespace App\Doctrine\Batch\Handler;

use Ang3\Doctrine\ORM\Batch\Handler\BatchHandlerInterface;

final class MyHandler implements BatchHandlerInterface
{
    public function __invoke(Iteration $iteration): void
    {
        // Data from the process iterator
        $data = $iteration->getData();

        // You can retrieve the entity manager from the iteration.
        $em = $iteration->getEntityManager();
    }
}
```

Use the trait `Ang3\Doctrine\ORM\Batch\Handler\BatchHandlerTrait` to enable options:

```
// ...
final class MyHandler implements BatchHandlerInterface
{
    // If you want to add options:
    use BatchHandlerTrait;

    // Internal constants used to define options
    private const OPTION_ENABLED = 'enabled';

    public function __invoke(Iteration $iteration): void
    {
        // Retrieves option values
        $enabled = $this->getOption(self::OPTION_ENABLED);

        // your logic with the option...
    }

    // Return the handler to allow chaining calls
    public function enableOption(bool $enabled = true): self
    {
       $this->setOption(self::OPTION_ENABLED, $enabled);

       return $this;
    }
}
```

#### Buffer size

[](#buffer-size)

You can modify the default buffer size:

```
$myProcess->setBufferSize(50); // By default: 20
```

#### Disable ID generators

[](#disable-id-generators)

You can turn off the ID generator for one or more entities, useful to migrate data.

```
$myProcess->disableIdGenerator(MyClass1::class, MyClass2::class/*, ...*/);
```

You can restore some disabled ID generators like below:

```
$myProcess->restoreIdGenerator(MyClass1::class, MyClass2::class/*, ...*/);

// ... Or restore all directly
$myProcess->restoreAllIdGenerators();
```

#### Transactional entities

[](#transactional-entities)

The entity manager could be cleared many times. That's why during the process, all entities loaded before the execution will be detached from the manager.

```
$myLoadedEntity; // attached
$myProcess->execute();
dump($myLoadedEntity); // Probably detached - If you persist, a new entity could be created!
```

To avoid reloading your entities, this component helps you to keep your entities in memory (by [variable reference](https://www.php.net/manual/fr/language.references.pass.php)) in order to reload it automatically.

```
$myLoadedEntity; // attached
$myProcess
    ->addTransactionalEntity($myLoadedEntity) // This variable is passed by reference
    ->execute();
dump($myLoadedEntity); // reloaded by the process on each flush/clear
```

#### On flush

[](#on-flush)

You can pass a callable to the batch to execute some logic on each flush/clear operations.

```
$myProcess->onFlush($myCallable);
```

Callable arguments:

1. `Ang3\Doctrine\ORM\Batch\BatchProcess` The current batch
2. `Ang3\Doctrine\ORM\Batch\BatchIteration|null` The iteration (NULL in case of last flush/clear).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1109d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7427494?v=4)[Joanis Rt](/maintainers/Ang3)[@Ang3](https://github.com/Ang3)

---

Top Contributors

[![Ang3](https://avatars.githubusercontent.com/u/7427494?v=4)](https://github.com/Ang3 "Ang3 (16 commits)")

### Embed Badge

![Health badge](/badges/ang3-doctrine-orm-batch-process/health.svg)

```
[![Health](https://phpackages.com/badges/ang3-doctrine-orm-batch-process/health.svg)](https://phpackages.com/packages/ang3-doctrine-orm-batch-process)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[api-platform/doctrine-orm

Doctrine ORM bridge

294.4M91](/packages/api-platform-doctrine-orm)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k12](/packages/2lenet-crudit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
