devture / silex-provider-doctrine-mongodb
Silex provider for MongoDB integration via Doctrine
Installs: 223
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/devture/silex-provider-doctrine-mongodb
Requires
- doctrine/mongodb: >=1.0,<1.7
This package is not auto-updated.
Last update: 2025-10-08 00:45:46 UTC
README
A doctrine/mongodb provider for the 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 services under the 'mongodb' namespace, with no custom configuration (empty array) $app->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 // See the docs for \MongoClient (http://php.net/MongoClient) for connection string format and options $configuration = [ 'server' => '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'); };