Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/spantaleev/silex-provider-doctrine-mongodb

Silex provider for MongoDB integration via Doctrine
https://github.com/spantaleev/silex-provider-doctrine-mongodb

Last synced: about 1 month ago
JSON representation

Silex provider for MongoDB integration via Doctrine

Awesome Lists containing this project

README

        

# Silex Doctrine-MongoDB Provider

A [doctrine/mongodb](https://github.com/doctrine/mongodb) provider for the [Silex](https://github.com/silexphp/Silex) micro-framework.

## Usage

Registering the provider creates a few services under a given *namespace*.
The provider can be registered multiple times if multiple connections are needed.

### Basic Usage

```php
register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', []));

// Get a reference to a database on that server connection
$app['db'] = function ($app) {
return $app['mongodb.connection']->selectDatabase('database_name');
};
```

### Advanced Usage

```php
'mongodb://example.com:27017',
'options' => [
'connect' => true,
'connectTimeoutMS' => 200,
],
];

$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', $configuration));

$app['db_main'] = function ($app) {
return $app['mongodb.connection']->selectDatabase('database_name');
};

$app['db_other'] = function ($app) {
return $app['mongodb.connection']->selectDatabase('another_database_name');
};
```