df / silex-doctrine-mongodb-provider
Silex Doctrine MongoDB Provider
1.0.1
2016-08-03 09:40 UTC
Requires
- php: ^5.5 || ^7.0
- alcaeus/mongo-php-adapter: 1.0.5
- doctrine/mongodb: ^1.3.0
- mongodb/mongodb: ^1.0.2
- pimple/pimple: ~3.0
- psr/log: 1.0.*
Requires (Dev)
- phpunit/phpunit: ^4.8
- silex/silex: ^2.0.2
Provides
- ext-mongo: 1.6.13
This package is not auto-updated.
Last update: 2024-09-14 19:42:13 UTC
README
这是Silex的一个MongoDB服务提供程序,基于Dominik Zogg [email protected] 优秀的存储库 saxulum-doctrine-mongodb-provider,包含一些改进和重构,以兼容silex 2.n/pimple 3.n和PHP 7.n
特性
- 支持Silex中的MongoDB(不提供ODM集成)
- 使用"alcaeus/mongo-php-adapter"作为已废弃的ext-mongo模块的包装器以支持PHP7
- ODM集成将由 df/silex-doctrine-mongodb-odm-provider 提供(查看详情)
要求
- PHP >= 5.5.n
- Silex 2.n (pimple 3.n)
- Doctrine MongoDb (>= 1.3.0)
安装
使用 composer 安装 df/silex-doctrine-mongodb-provider.
composer require df/silex-doctrine-mongodb-provider
设置
- 一个连接的示例
$app->register(new DoctrineMongoDbProvider(), [
'mongodb.options' => [
'server' => 'mongodb://localhost:27017',
'options' => [
'username' => 'your-username',
'password' => 'your-password',
'db' => 'mongo_db_01'
]
]
]);
- 多个连接的示例
$app->register(new DoctrineMongoDbProvider(), [
'mongodbs.options' => [
'mongodb1' => [
'server' => 'mongodb://localhost:27017',
'options' => [
'username' => 'your-username',
'password' => 'your-username',
'db' => 'mongo_db_01'
]
],
'mongodb2' => [
'server' => 'mongodb://localhost:27018',
'options' => [
'username' => 'your-username',
'password' => 'your-username',
'db' => 'mongo_db_02'
]
]
]
));
使用方法
- 一个连接的示例
$document = ['key' => 'value'];
$app['mongodb']
->selectDatabase('mongo_db_01')
->selectCollection('sample')
->insert($document)
;
- 多个连接的示例
$document = ['key' => 'value'];
$app['mongodbs']['mongo1']
->selectDatabase('mongo_db_01')
->selectCollection('sample')
->insert($document)
;
版权
- Patrick Paechnatz [email protected]
- Dominik Zogg [email protected](原始服务提供程序作者)
- Fabien Potencier [email protected](DoctrineServiceProvider,Logger)
- Kris Wallsmith [email protected](Logger)