PHPackages                             neutron/mongo-odm-silex-provider - 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. neutron/mongo-odm-silex-provider

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

neutron/mongo-odm-silex-provider
================================

MongoODM Silex service provider

0.1.3(12y ago)3615.8k15[3 issues](https://github.com/romainneutron/MongoDB-ODM-Silex-Provider/issues)MITPHPPHP &gt;=5.3.2

Since Feb 7Pushed 12y ago3 watchersCompare

[ Source](https://github.com/romainneutron/MongoDB-ODM-Silex-Provider)[ Packagist](https://packagist.org/packages/neutron/mongo-odm-silex-provider)[ RSS](/packages/neutron-mongo-odm-silex-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

MongoDB ODM Silex Service Provider
==================================

[](#mongodb-odm-silex-service-provider)

[![Build Status](https://camo.githubusercontent.com/78648d8d0937a0dd7f01ceb0ddf5c9c3b8db5e1682d5a1db0403942be6104a1a/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f726f6d61696e6e657574726f6e2f4d6f6e676f44422d4f444d2d53696c65782d50726f76696465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/romainneutron/MongoDB-ODM-Silex-Provider)

This [Silex](silex.sensiolabs.org/) service provider provides Doctrine [MongoDB ODM](http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/index.html)service in your Silex Application.

This provider has been developed by [Justin Hileman](https://github.com/bobthecow/SilexExtensions/tree/master/DoctrineMongoDB/src)and [Florian Klein](https://github.com/docteurklein/SilexServiceProviders/tree/master/DoctrineMongoDB/src)

It seems that both of these projects are not maintained anymore, so here comes the maintained version, compatible with Doctrine MongoDB ODM &gt;= 1.0.0-beta4.

Enjoy

Usage
=====

[](#usage)

Composer
--------

[](#composer)

Add in your `composer.json` the require entry for this library.

```
{
    "require": {
        "neutron/mongo-odm-silex-provider": "*"
    }
}
```

and run `composer install` (or `update`) to download all files, resolve dependencies and update the autoloading.php file.

Registering
-----------

[](#registering)

You can register MongoDB ODM Provider using:

```
use Neutron\Silex\Provider\MongoDBODMServiceProvider;

// ...

$app->register(new MongoDBODMServiceProvider(), array(
    'doctrine.odm.mongodb.connection_options' => array(
        'database' => 'MONGODB_DB',

        // connection string:
        // mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db
        'host'     => 'MONGODB_SERVER',

        // connection options as described here:
        // http://www.php.net/manual/en/mongoclient.construct.php
        'options'  => array('fsync' => false)
    ),
    'doctrine.odm.mongodb.documents'               => array(),
    'doctrine.odm.mongodb.proxies_dir'             => 'cache/doctrine/odm/mongodb/Proxy',
    'doctrine.odm.mongodb.proxies_namespace'       => 'DoctrineMongoDBProxy',
    'doctrine.odm.mongodb.auto_generate_proxies'   => true,
    'doctrine.odm.mongodb.hydrators_dir'           => 'cache/doctrine/odm/mongodb/Hydrator',
    'doctrine.odm.mongodb.hydrators_namespace'     => 'DoctrineMongoDBHydrator',
    'doctrine.odm.mongodb.auto_generate_hydrators' => true,
    'doctrine.odm.mongodb.metadata_cache'          => new \Doctrine\Common\Cache\ArrayCache(),
    'doctrine.odm.mongodb.logger_callable'         => $app->protect(function($query) {
                                                          // log your query
                                                      }),
));
```

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

[](#configuration)

The configuration params listed above can be omitted if you use the default values.

- `doctrine.odm.mongodb.documents`: document management registration. This option will be explaned in the next praragraph.
- `doctrine.odm.mongodb.proxies_dir`: directory for proxy classes generated by Doctrine.
- `doctrine.odm.mongodb.proxies_namespace`: namespace for proxy classes generated by Doctrine.
- `doctrine.odm.mongodb.hydrators_dir`: directory for hydrators classes generated by Doctrine.
- `doctrine.odm.mongodb.hydrators_namespace`: namespace for hydrators classes generated by Doctrine.
- `doctrine.odm.mongodb.metadata_cache`: instace of class to use as caching system. Maybe you can change to `\Doctrine\Common\Cache\ApcCache()` to use APC caching system.
- `doctrine.odm.mongodb.logger_callable`: Callable used for logging, must wrap functions using $app-&gt;protect() to prevent from them being interpreted by Pimple

Document registration
---------------------

[](#document-registration)

You need to register the differents documents namespace to make possible use it with Doctrine ODM, eg:

```
$app->register(new MongoDBODMServiceProvider(), array(
    // ...
    'doctrine.odm.mongodb.documents' => array(
        0 => array(
            'type' => 'annotation',
            'path' => array(
                'src/Acme/Entities',
            ),
            'namespace' => 'Acme/Entities',
            'alias'     => 'docs',
        ),
    ),
    // ...
));
```

you can add multiple folders/namespaces.

Usage
-----

[](#usage-1)

Add information in MongoDB:

```
// Define routing
$app->post('/demo/add', function () use ($app) {
  // ...
  $demo = new \Acme\Document\Demo();
  $demo->setTitle('Test');
  $demo->setBody('This is a demo document.');

  $app['doctrine.odm.mongodb.dm']->persist($demo);
  $app['doctrine.odm.mongodb.dm']->flush();

  // ...
});
```

Retrieve information from MongoDB:

```
$app->get('/demo/list', function () use ($app) {
  // ...
  $demos = $app['doctrine.odm.mongodb.dm']
    ->getRepository('Acme\\Document\\Demo')
    ->findAll();

  // ...
});
```

if you have defined an alias, you can use it:

```
$app['doctrine.odm.mongodb.dm']->getRepository('docs:Demo');
```

Creating console
----------------

[](#creating-console)

Sometime can be usefull have console to manage your Doctrine ODM. You can configure your console to use it with:

```
use Symfony\Component\Console\Application;
// .. other class to import
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper;

$console = new Application('Acme Application', '1.0');

// Other commands

// This make possibile to re-use default Doctrine console command
$dm = new DocumentManagerHelper($app['doctrine.odm.mongodb.dm']);
$console->getHelperSet()->set($dm, 'dm');

// Add Doctrine ODM commands
$console->addCommands(array(
    new Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateDocumentsCommand(),
    new Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateHydratorsCommand(),
    new Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(),
    new Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(),
    new Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(),
    new Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand(),
));
```

License
=======

[](#license)

Released under the MIT license

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.3% 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 ~144 days

Total

4

Last Release

4407d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c264f69af4c60cb9cc98a522b4663f4b6a2708629cabc14409478ab6fc35348?d=identicon)[romain](/maintainers/romain)

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (33 commits)")[![myurasov](https://avatars.githubusercontent.com/u/224567?v=4)](https://github.com/myurasov "myurasov (8 commits)")[![mavimo](https://avatars.githubusercontent.com/u/43941?v=4)](https://github.com/mavimo "mavimo (3 commits)")[![cranberyxl](https://avatars.githubusercontent.com/u/63764?v=4)](https://github.com/cranberyxl "cranberyxl (2 commits)")[![MDrollette](https://avatars.githubusercontent.com/u/329784?v=4)](https://github.com/MDrollette "MDrollette (2 commits)")[![lucianodelucchi](https://avatars.githubusercontent.com/u/579642?v=4)](https://github.com/lucianodelucchi "lucianodelucchi (1 commits)")

---

Tags

doctrineodmsilex

### Embed Badge

![Health badge](/badges/neutron-mongo-odm-silex-provider/health.svg)

```
[![Health](https://phpackages.com/badges/neutron-mongo-odm-silex-provider/health.svg)](https://phpackages.com/packages/neutron-mongo-odm-silex-provider)
```

###  Alternatives

[gedmo/doctrine-extensions

Doctrine behavioral extensions

4.1k118.8M366](/packages/gedmo-doctrine-extensions)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86676.6k35](/packages/doctrine-doctrine-mongo-odm-module)

PHPackages © 2026

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