PHPackages                             juliangut/doctrine-manager-builder - 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. juliangut/doctrine-manager-builder

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

juliangut/doctrine-manager-builder
==================================

Doctrine2 managers builder

1.8.1(7y ago)02.1k[2 issues](https://github.com/juliangut/doctrine-manager-builder/issues)1BSD-3-ClausePHPPHP ^5.6|^7.0

Since Sep 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/juliangut/doctrine-manager-builder)[ Packagist](https://packagist.org/packages/juliangut/doctrine-manager-builder)[ Docs](https://github.com/juliangut/doctrine-manager-builder)[ RSS](/packages/juliangut-doctrine-manager-builder/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (12)Versions (18)Used By (1)

[![PHP version](https://camo.githubusercontent.com/957f92835f932441645ace4028bd11ed80ce25423944116fd564de89986db110/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344352e362d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/4323f2247929c08549560d90541a707486d8d26326e927dfa6f3d6d743a55b0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/doctrine-manager-builder)[![License](https://camo.githubusercontent.com/8f74160217ae2409a5b343d210bcaa2e970c4ff29166a387a9b68197ec59a779/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://github.com//doctrine-manager-builder/blob/master/LICENSE)

[![Build Status](https://camo.githubusercontent.com/96741c5bdcf7a39044798fff6a613930d5d7b8de52035faed436ff961220a13a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/juliangut/doctrine-manager-builder)[![Style Check](https://camo.githubusercontent.com/c20747df5d7d6b6d62666e48bebef2b363bb535c939dbaf5e031626287a48e67/68747470733a2f2f7374796c6563692e696f2f7265706f732f36373934373130302f736869656c64)](https://styleci.io/repos/67947100)[![Code Quality](https://camo.githubusercontent.com/186233ef518870028251b08a5adf76a66c83eedf050d8b5b9c8ec53ddbf83aba/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/doctrine-manager-builder)[![Code Coverage](https://camo.githubusercontent.com/12776239197a4d149e5fbf11734098f03c469d83d9334aedd27c92236d150564/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/juliangut/doctrine-manager-builder)

[![Total Downloads](https://camo.githubusercontent.com/22c5cf0f62634dd8c9373547370eb942e8226cda9261ac069392622e7de16a9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/doctrine-manager-builder)[![Monthly Downloads](https://camo.githubusercontent.com/5c7912c3f3bd34bd40ea90d3222d76ccf5bc49093397575fcfa7a48b26b87ea7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a756c69616e6775742f646f637472696e652d6d616e616765722d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/doctrine-manager-builder)

Doctrine2 managers builder
==========================

[](#doctrine2-managers-builder)

Frees you from the tedious work of configuring Doctrine's managers, ORM Entity Manager, MongoDB Document Manager and CouchDB Document Manager.

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

[](#installation)

### Composer

[](#composer)

```
composer require juliangut/doctrine-manager-builder

```

If using MongoDB on PHP &gt;= 7.0

```
composer require alcaeus/mongo-php-adapter --ignore-platform-reqs

```

Usage
-----

[](#usage)

### Relational Database Entity Manager

[](#relational-database-entity-manager)

```
use Jgut\Doctrine\ManagerBuilder\ManagerBuilder;
use Jgut\Doctrine\ManagerBuilder\RelationalBuilder;

$rdbmsBuilder = new RelationalBuilder([
    'annotation_autoloaders' => ['class_exists'],
    'connection' => [
        'driver' => 'pdo_sqlite',
        'memory' => true,
    ],
    'metadata_mapping' => [
        [
            'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
            'path' => 'path/to/entities',
        ],
    ],
]);
```

### MongoDB Document Manager

[](#mongodb-document-manager)

```
use Jgut\Doctrine\ManagerBuilder\ManagerBuilder;
use Jgut\Doctrine\ManagerBuilder\MongoDBBuilder;

$mongoDBBuilder = new MongoDBBuilder([
    'annotation_autoloaders' => ['class_exists'],
    'connection' => [
        'server' => 'mongodb://localhost:27017',
        'options' => ['connect' => false],
    ],
    'metadata_mapping' => [
        [
            'driver' => new \Doctrine\ORM\Mapping\Driver\YamlDriver(
                'path/to/document/yaml/mapping/files',
                '.yml'
            ),
        ],
        [
            'type' => ManagerBuilder::METADATA_MAPPING_PHP,
            'path' => 'path/to/document/php/mapping/files',
            'namespace' => 'Project\Document\Namespace',
        ],
    ],
]);
$documentManager = $mongoDBBuilder->getManager();
```

### CouchDB Document Manager

[](#couchdb-document-manager)

```
use Jgut\Doctrine\ManagerBuilder\CouchDBBuilder;
use Jgut\Doctrine\ManagerBuilder\MongoDBBuilder;

$couchDBBuilder = new CouchDBBuilder([
    'annotation_autoloaders' => ['class_exists'],
    'connection' => [
        'host' => 'localhost',
        'dbname' => 'doctrine',
    ],
    'metadata_mapping' => [
        [
            'type' => ManagerBuilder::METADATA_MAPPING_XML,
            'path' => 'path/to/document/xml/mapping/files',
            'extension' => '.xml',
        ],
    ],
]);
$documentManager = $couchDBBuilder->getManager();
```

**Mind that Doctrine CouchDB ODM support is not as good/wide as in Doctrine ORM or Doctrine MongoDB ODM**

Configuration
-------------

[](#configuration)

### Common

[](#common)

- `metadata_mapping` **REQUIRED** array of metadata mapping drivers or configurations to create them, *see note below*
- `annotation_files` array of Doctrine annotations files
- `annotation_namespaces` array of Doctrine annotations namespaces
- `annotation_autoloaders` array of Doctrine annotations auto-loader callable
- `proxies_path` path were Doctrine creates its proxy classes, defaults to /tmp
- `proxies_namespace` string for proxies namespace
- `proxies_auto_generation` integer indicating proxy auto generation behavior
- `metadata_cache_driver` \\Doctrine\\Common\\Cache\\CacheProvider metadata cache driver
- `metadata_cache_namespace` string for metadata cache namespace (different for each type of manager)
- `event_manager` a configured `Doctrine\Common\EventManager`
- `event_subscribers` an array of custom `Doctrine\Common\EventSubscriber`

### Relational ORM Entity Manager

[](#relational-orm-entity-manager)

- `connection` **REQUIRED** array of PDO configurations or a \\Doctrine\\DBAL\\Connection. See [supported drivers](http://php.net/manual/en/pdo.drivers.php)
- `query_cache_driver` \\Doctrine\\Common\\Cache\\CacheProvider query cache driver, defaults to `metadata_cache_driver`
- `query_cache_namespace` string for query cache namespace, defaults to 'DoctrineRDBMSORMQueryCache'
- `result_cache_driver` \\Doctrine\\Common\\Cache\\CacheProvider result cache driver, defaults to `metadata_cache_driver`
- `result_cache_namespace` string for result cache namespace, defaults to 'DoctrineRDBMSORMResultCache'
- `hydrator_cache_driver` \\Doctrine\\Common\\Cache\\CacheProvider hydrator cache driver, defaults to `metadata_cache_driver`
- `hydrator_cache_namespace` string for hydrator cache namespace, defaults to 'DoctrineRDBMSORMHydratorCache'
- `repository_factory` \\Doctrine\\ORM\\Repository\\RepositoryFactory
- `default_repository_class` \\Doctrine\\ORM\\EntityRepository
- `naming_strategy` a `\Doctrine\ORM\Mapping\NamingStrategy`, defaults to `UnderscoreNamingStrategy`
- `quote_strategy` a `\Doctrine\ORM\Mapping\QuoteStrategy`, defaults to `DefaultQuoteStrategy`
- `second_level_cache_configuration` a `\Doctrine\ORM\Cache\CacheConfiguration`
- `sql_logger` a `\Doctrine\DBAL\Logging\SQLLogger`
- `custom_types` array of `'type_name' => '\Doctrine\DBAL\Types\Type'`
- `custom_mapping_types` array of `'type_name' => 'Doctrine type: a constant on \Doctrine\DBAL\Types\Type'`. Used in conjunction with custom\_types
- `custom_filters` array of custom `'filter_name' => '\Doctrine\ORM\Query\Filter\SQLFilter'`
- `string_functions` array of custom `'function_name' => '\Doctrine\ORM\Query\AST\Functions\FunctionNode'` for string DQL functions
- `numeric_functions` array of custom `'function_name' => '\Doctrine\ORM\Query\AST\Functions\FunctionNode'` for numeric DQL functions
- `datetime_functions` array of custom `'function_name' => '\Doctrine\ORM\Query\AST\Functions\FunctionNode'` for datetime DQL functions

### MongoDB ODM Document Manager

[](#mongodb-odm-document-manager)

- `connection` **REQUIRED** array of \\MongoClient configurations (server and options) or a \\Doctrine\\MongoDB\\Connection
- `default_database` **REQUIRED** default database to be used in case none specified
- `hydrators_path` path where Doctrine creates its hydrator classes, defaults to /tmp
- `hydrators_namespace` string for hydrators namespace, defaults to 'DoctrineMongoDBODMHydrator'
- `hydrators_auto_generation` integer indicating hydrators auto generation behavior
- `persistent_collections_path` path where Doctrine creates its persistent collection classes, defaults to /tmp
- `persistent_collections_namespace` string for persistent collections namespace, defaults to 'DoctrineMongoDBODMPersistentCollection'
- `persistent_collections_auto_generation` integer persistent collections auto generation behavior
- `repository_factory` \\Doctrine\\ODM\\MongoDB\\Repository\\RepositoryFactory
- `default_repository_class` \\Doctrine\\ODM\\MongoDB\\DocumentRepository
- `logger_callable` valid callable
- `custom_types` array of `'type_name' => '\Doctrine\ODM\MongoDB\Types\Type'`
- `custom_filters` array of custom `'filter_name' => '\Doctrine\ODM\MongoDB\Query\Filter\BsonFilter'`

### CouchDB ODM Document Manager

[](#couchdb-odm-document-manager)

- `connection` **REQUIRED** array of \\Doctrine\\CouchDB\\CouchDBClient configurations or a \\Doctrine\\CouchDB\\CouchDBClient
- `repository_factory` \\Jgut\\Doctrine\\ManagerBuilder\\CouchDB\\Repository\\RepositoryFactory
- `default_repository_class` \\Doctrine\\ODM\\CouchDB\\DocumentRepository
- `lucene_handler_name` Apache Lucene handler name

### Considerations

[](#considerations)

- Make sure you always provide an `annotation_autoloader` callable to fallback in loading annotations, typically it will be 'class\_exists'. If creating various managers this should be added to the last one generated.
- `metadata_mapping` must be an array containing arrays of configurations to create MappingDriver objects:
    - `type` one of \\Jgut\\Doctrine\\ManagerBuilder\\ManagerBuilder constants: `METADATA_MAPPING_ANNOTATION`, `METADATA_MAPPING_XML`, `METADATA_MAPPING_YAML` or `METADATA_MAPPING_PHP` **REQUIRED if no driver**
    - `path` a string path or array of paths to where mapping files are **REQUIRED if no driver**
    - `extension` overrides default mapping file extension: '.dcm.xml' for XML files and '.dcm.yml' for YAML files
    - `namespace` the namespace under which the mapped classes are **REQUIRED only if more than ONE mapping driver is defined**
    - `driver` an already created \\Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver object **REQUIRED if no type AND path**
- `metadata_cache_driver`, if not provided, is automatically generated in the following order based on availability: `ApcuCache`, `XcacheCache`, `MemcacheCache`, `RedisCache` and finally fallback to `ArrayCache` which is always available. Any other cache driver not provided will fallback to using a clone of metadata cache driver.
- `proxies_auto_generation`, `hydrators_auto_generation` and `persistent_collections_auto_generation` configuration values are Doctrine\\Common\\Proxy\\AbstractProxyFactory constants, in all cases it defaults to `AUTOGENERATE_NEVER`.

Managers are being configured **ready for production**, this means proxies, hydrators and persisten collections won't be automatically generated and, in case no cache driver is provided, one will be auto-generated. It is recommended you always provide your cache provider. For development you should use `VoidCache`.

Extending managers
------------------

[](#extending-managers)

Extending default managers with extra features is extremely easy. Lets see two examples with well-known libraries.

### Adding new types

[](#adding-new-types)

Using [ramsey/uuid-doctrine](https://github.com/ramsey/uuid-doctrine)

```
composer require ramsey/uuid-doctrine

```

```
use Jgut\Doctrine\ManagerBuilder\RelationalBuilder;
use Ramsey\Uuid\Doctrine\UuidType;

require __DIR__ . '/vendor/autoload.php';

$rdbmsBuilder = new RelationalBuilder([
    'annotation_autoloaders' => ['class_exists'],
    'connection' => [
        'driver' => 'pdo_sqlite',
        'memory' => true,
    ],
    'metadata_mapping' => [
        [
            'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
            'path' => 'path/to/entities',
        ],
    ],
    // Register UUID as custom type
    'custom_types' => ['uuid' => UuidType::class],
]);
$entityManager = $rdbmsBuilder->getManager();
```

### Adding new behaviour

[](#adding-new-behaviour)

Using [gedmo/doctrine-extensions](https://github.com/Atlantic18/DoctrineExtensions)

```
composer require gedmo/doctrine-extensions

```

```
use Gedmo\DoctrineExtensions;
use Gedmo\Sluggable\SluggableListener;
use Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter;
use Gedmo\SoftDeleteable\SoftDeleteableListener;
use Gedmo\Timestampable\TimestampableListener;
use Jgut\Doctrine\ManagerBuilder\RelationalBuilder;

require __DIR__ . '/vendor/autoload.php';

$rdbmsBuilder = new RelationalBuilder([
    'annotation_autoloaders' => ['class_exists'],
    'connection' => [
        'driver' => 'pdo_sqlite',
        'memory' => true,
    ],
    'metadata_mapping' => [
        [
            'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
            'path' => 'path/to/entities',
        ],
    ],
    // Register new doctrine behaviours
    'event_subscribers' => [
        new SluggableListener,
        new TimestampableListener,
        new SoftDeleteableListener,
    ],
    // Register custom filters
    'custom_filters' => [
        'soft-deleteable' => SoftDeleteableFilter::class,
    ],
]);

// Register mapping driver into DoctrineExtensions
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($rdbmsBuilder->getMetadataMappingDriver());

// Get entity manager as usual
$entityManager = $rdbmsBuilder->getManager();
```

Console integration
-------------------

[](#console-integration)

Although Doctrine ORM comes with a great CLI tool this library is intended to be used without ORM, and thus a new tool has been created instead of forcing to require Doctrine ORM.

This new CLI tool (doctrine-manager) is more powerful in the sense that it runs the same commands for different databases (managers) of the same kind by providing \\Jgut\\Doctrine\\ManagerBuilder\\ConsoleBuilder with named builders.

The configuration of `doctrine-manager` tool resembles the one ORM comes with and so you must have a 'cli-config.php' or ' config/cli-config.php' file

The only difference is that here you must return an instance of Symfony\\Component\\Console\\Application instead of a Symfony\\Component\\Console\\Helper\\HelperSet

```
use Jgut\Doctrine\ManagerBuilder\ConsoleBuilder;
use Jgut\Doctrine\ManagerBuilder\RelationalBuilder;

require __DIR__ . '/vendor/autoload.php';

$settings = require 'managers-configurations.php';

$consoleBuilder = new ConsoleBuilder;
$consoleBuilder->addBuilder(new RelationalBuilder($settings['main'], 'one'));
$consoleBuilder->addBuilder(new RelationalBuilder($settings['secondary'], 'two'));

return $consoleBuilder->getApplication();
```

If you run `./vendor/bin/doctrine-manager list` you will find the commands prefixed with builder's name, so commands are run with different managers

```
Available commands:
...
 dbal
  dbal:one:import               Import SQL file(s) directly to Database.
  dbal:one:run-sql              Executes arbitrary SQL directly from the command line.
  dbal:two:import               Import SQL file(s) directly to Database.
  dbal:two:run-sql              Executes arbitrary SQL directly from the command line.
  ...
 orm
  orm:one:clear-cache:metadata  Clear all metadata cache of the various cache drivers.
  orm:one:clear-cache:query     Clear all query cache of the various cache drivers.
  orm:two:clear-cache:metadata  Clear all metadata cache of the various cache drivers.
  orm:two:clear-cache:query     Clear all query cache of the various cache drivers.
  ...

```

*doctrine-manager only allows named manager builders*

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/juliangut/doctrine-manager-builder/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/juliangut/doctrine-manager-builder/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/juliangut/doctrine-manager-builder/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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

Every ~200 days

Recently: every ~749 days

Total

17

Last Release

371d ago

Major Versions

0.2 → 1.02016-09-18

1.8.1 → 2.x-dev2025-06-24

PHP version history (3 changes)0.1PHP &gt;=5.6

1.6PHP ^5.6|^7.0

2.x-devPHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (100 commits)")

---

Tags

doctrinedoctrine-couchdb-odmdoctrine-mongodb-odmdoctrine-ormdocument-managerentity-managerdbalcouchdbdoctrine2mongodbrelationalentity-managerDocument Manager

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/juliangut-doctrine-manager-builder/health.svg)

```
[![Health](https://phpackages.com/badges/juliangut-doctrine-manager-builder/health.svg)](https://phpackages.com/packages/juliangut-doctrine-manager-builder)
```

###  Alternatives

[friendsofsymfony/elastica-bundle

Elasticsearch PHP integration for your Symfony project using Elastica

1.3k17.7M49](/packages/friendsofsymfony-elastica-bundle)

PHPackages © 2026

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