Mongo service provider for the Silex framework. Tested this PHP7 & last MongoDB driver.
Add in your composer.json
the require entry for this library.
{
"require": {
"moriony/silex-mongo-provider": "*"
}
}
and run composer install
(or update
) to download all files.
$app->register(new MongoServiceProvider, array(
'mongo.connections' => array(
'default' => array(
'server' => "mongodb://localhost:27017",
'options' => array("connect" => true)
)
),
));
$connections = $app['mongo'];
$defaultConnection = $connections['default'];
$mongoFactory = $app['mongo.factory'];
$customConnection = $mongoFactory("mongodb://localhost:27017", array("connect" => true));