PHPackages                             juliangut/slim-doctrine - 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. [Framework](/categories/framework)
4. /
5. juliangut/slim-doctrine

ActiveLibrary[Framework](/categories/framework)

juliangut/slim-doctrine
=======================

Slim-Doctrine managers integration

2.3(8y ago)153.7k↓50%5[1 issues](https://github.com/juliangut/slim-doctrine/issues)BSD-3-ClausePHPPHP ^5.6|^7.0

Since Sep 6Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/juliangut/slim-doctrine)[ Packagist](https://packagist.org/packages/juliangut/slim-doctrine)[ Docs](http://github.com/juliangut/slim-doctrine)[ RSS](/packages/juliangut-slim-doctrine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (25)Used By (0)

[![PHP version](https://camo.githubusercontent.com/957f92835f932441645ace4028bd11ed80ce25423944116fd564de89986db110/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344352e362d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/78ad50dc636a72a0e0c0ee761f588bff046306f535490e1ed6feb1b4b8c26e83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-doctrine)[![License](https://camo.githubusercontent.com/07b76ab9faacd0476259b68adb9681622e1453d21e2824afd89ddd609b1cf27e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://github.com/juliangut/slim-doctrine/blob/master/LICENSE)

[![Build Status](https://camo.githubusercontent.com/759ae4186a7ad3f076a094ec2d71d0eb16eced092cba95f43a45b7fb1c00939b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/juliangut/slim-doctrine)[![Style Check](https://camo.githubusercontent.com/a6683448011b2480850f0ec32e2fd51a4ef2b44cac1ea65fee9a92e432eed05a/68747470733a2f2f7374796c6563692e696f2f7265706f732f34323031343432392f736869656c64)](https://styleci.io/repos/42014429)[![Code Quality](https://camo.githubusercontent.com/2d2ce50418a4e3361f80346ffb6c584bbd0e9993a45fee1ccae7c9eb2d08c780/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/juliangut/slim-doctrine)[![Code Coverage](https://camo.githubusercontent.com/ccb4cecd09b838e0cfd28ded38f5800a12d22e176d92cc24ee5749cea5999ae7/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/juliangut/slim-doctrine)

[![Total Downloads](https://camo.githubusercontent.com/5a808e6a48d3ddd276afd538620745b6d1d4d5cd0bf453077f436455180c7fbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-doctrine)[![Monthly Downloads](https://camo.githubusercontent.com/c9a2f5cd3cbf8e4b6e59ef5f9b74a1fa392e6f01b074f2f6dfbab14eecf08eb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a756c69616e6775742f736c696d2d646f637472696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-doctrine)

Slim integration with Doctrine managers
=======================================

[](#slim-integration-with-doctrine-managers)

Easy Slim framework integration with Doctrine's Entity Manager, MongoDB Document Manager and CouchDB Document Manager.

Important note
--------------

[](#important-note)

The latest version of slim-doctrine is focused only on Slim framework and Doctrine integration, and thus using the manager builders as stand alone is not possible.

That same functionality can be achieved by using [juliangut/doctrine-manager-builder](https://github.com/juliangut/doctrine-manager-builder) which is not tied to Slim framework.

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

[](#installation)

Best way to install is using [Composer](https://getcomposer.org/):

```
composer require juliangut/slim-doctrine

```

Then require\_once the autoload file:

```
require_once './vendor/autoload.php';
```

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

[](#configuration)

Each kind of manager has its configurations stored on a key in the settings array

- `ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY` ("entity\_manager") for `ORM`
- `ManagerBuilder::DEFAULT_MONGODB_MANAGER_KEY` ("mongodb\_document\_manager") for `MongoDB ODM`
- `ManagerBuilder::DEFAULT_COUCHDB_MANAGER_KEY` ("couchdb\_document\_manager") for `CouchDB ODM`

```
[
    ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY => [
        'manager1_name' => ,
        'manager2_name' => ,
        ...
    ],
    ManagerBuilder::DEFAULT_MONGODB_MANAGER_KEY => [
        'manager3_name' => ,
        'manager4_name' => ,
        ...
    ],
    ManagerBuilder::DEFAULT_COUCHDB_MANAGER_KEY => [
        'manager5_name' => ,
        'manager6_name' => ,
        ...
    ],
]
```

If a manager is not given a name then a default one will be used:

- `ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_NAME` ("entityManager) for `ORM`
- `ManagerBuilder::DEFAULT_MONGODB_MANAGER_NAME` ("mongoDocumentManager") for `MongoDB ODM`
- `ManagerBuilder::DEFAULT_COUCHDB_MANAGER_NAME` ("couchDocumentManager") for `CouchDB ODM`

### Options

[](#options)

ManagerBuilder's default keys and manager names can be modified providing constructor with an options array to change any of them

```
$options = [
    ManagerBuilder::RELATIONAL_MANAGER_KEY => 'entity_manager',
    ManagerBuilder::MONGODB_MANAGER_KEY => 'mongodb_document_manager',
    ManagerBuilder::COUCHDB_MANAGER_KEY => 'couchdb_document_manager',
    ManagerBuilder::RELATIONAL_MANAGER_NAME => 'entityManager',
    ManagerBuilder::MONGODB_MANAGER_NAME => 'mongoDocumentManager',
    ManagerBuilder::COUCHDB_MANAGER_NAME => 'couchDocumentManager',
];
$managerBuilder = new ManagerBuilder($options);
```

### Manager builders

[](#manager-builders)

In order to configure the different Doctrine manager builders head to [juliangut/doctrine-manager-builder](https://github.com/juliangut/doctrine-manager-builder) which is used in this package.

Usage
-----

[](#usage)

Register managers in the DI container as any other service.

```
use Jgut\Slim\Doctrine\ManagerBuilder;
use Slim\App;

// Loaded from a file
$settings = [
    'my_custom_key' => [
        'annotation_autoloaders' => ['class_exists'],
        'connection' => [
            'driver' => 'pdo_sqlite',
            'memory' => true,
        ],
        'metadata_mapping' => [
            [
                'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                'path' => 'path/to/annotation/mappings',
            ],
        ],
    ],
];

$managerBuilder = new ManagerBuilder([ManagerBuilder::RELATIONAL_MANAGER_KEY => 'my_custom_key']);
$managerBuilder->loadSettings($settings);

// Create Slim app and fetch DI Container
$app = new App();
$container = $app->getContainer();

// Register every manager in the container
foreach ($managerBuilder->getManagers() as $name => $manager) {
    $container[$name] = $manager;
}

// Use managers
$app->get('/', function () {
    $this->entityManager->persist(new \Entity);
    $this->entityManager->flush();
});
```

Register manager builder in the DI container to delegate managers creation.

```
use Jgut\Slim\Doctrine\ManagerBuilder;
use Interop\Container\ContainerInterface;
use Slim\App;

// Probably loaded from a file...
$settings = [
    'settings.doctrineManagers' => [
        ManagerBuilder::DEFAULT_RELATIONAL_MANAGER_KEY => [
            'mainDocumentManager' => [
                'connection' => [
                    'server' => 'mongodb://localhost:27017',
                ],
                'metadata_mapping' => [
                    [
                        'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                        'path' => 'path/to/annotation/mappings',
                    ],
                ],
            ],
            'secondaryDocumentManager' => [
                'annotation_autoloaders' => ['class_exists'],
                'connection' => [
                    'server' => 'mongodb://localhost:27017',
                ],
                'metadata_mapping' => [
                    [
                        'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
                        'path' => 'path/to/annotation/mappings',
                    ],
                ],
            ],
        ],
    ],
];

// Create Slim app and fetch DI Container
$app = new App($settings);
$container = $app->getContainer();

// Register manager builder fetching settings from container
$container['manager_builder'] => function (ContainerInterface $container) {
    return (new ManagerBuilder())->loadSettings($container->get('settings.doctrineManagers'));
};

// Register managers by pulling them from the builder
$container['mainDocumentManager'] => function (ContainerInterface $container) {
    return $container->get('manager_builder')->getManager('mainDocumentManager');
};
$container['secondaryDocumentManager'] => function (ContainerInterface $container) {
    return $container->get('manager_builder')->getManager('secondaryDocumentManager');
};

// Use managers
$app->get('/', function () {
    $this->mainDocumentManager->persist(new \Document);
    $this->mainDocumentManager->flush();
});
```

CLI Application builder
-----------------------

[](#cli-application-builder)

`doctrine-manager` is a CLI tool that is installed with this package. It provides the same functionality that Doctrine's ORM `doctrine` CLI tool does but it does not need ORM to be installed. Additionally `doctrine-manager` allows you to have numerous managers configured thanks to prepending manager name.

The way to using `doctrine-manager` is the same as with `doctrine` by creating a `cli-config.php` file returning a Symfony\\Component\\Console\\Application

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

use Jgut\Slim\Doctrine\ManagerBuilder;

$settings = require 'configurations.php';

$managerBuilder = (new ManagerBuilder())->loadSettings($settings);

return $managerBuilder->getCLIApplication();
```

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

[](#contributing)

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

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

### Contributors

[](#contributors)

- [@mcrauwel (Matthias Crauwels)](https://github.com/mcrauwel)

License
-------

[](#license)

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

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 96.5% 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 ~155 days

Recently: every ~793 days

Total

24

Last Release

328d ago

Major Versions

0.8 → 1.02016-02-14

1.4 → 2.0-rc.12016-09-18

2.3 → 3.x-dev2025-06-24

PHP version history (5 changes)0.1PHP &gt;=5.4

0.3.1PHP &gt;=5.5

2.0-rc.1PHP &gt;=5.6

2.3PHP ^5.6|^7.0

3.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 (109 commits)")[![ne0h12](https://avatars.githubusercontent.com/u/5797539?v=4)](https://github.com/ne0h12 "ne0h12 (2 commits)")[![nogo](https://avatars.githubusercontent.com/u/305163?v=4)](https://github.com/nogo "nogo (2 commits)")

---

Tags

doctrineintegrationmanagerslim-frameworkframeworkslimdoctrinehandler

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3708.0M210](/packages/slim-twig-view)[gotzmann/comet

Modern PHP framework for building blazing fast REST APIs and microservices

68816.2k1](/packages/gotzmann-comet)[patricksavalle/slim-rest-api

Production-grade REST-API App-class for PHP SLIM, in production on https://zaplog.pro (https://api.zaplog.pro/v1)

101.4k](/packages/patricksavalle-slim-rest-api)

PHPackages © 2026

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