cimrie / odm
Doctrine MongoDB ODM 与 Laravel 的集成。旨在与其他框架兼容。
v0.2.10
2017-05-05 09:16 UTC
Requires
- ext-mongo: *
- alcaeus/mongo-php-adapter: ^1.0
- doctrine/mongodb: ^1.4
- doctrine/mongodb-odm: ^1.1
- gedmo/doctrine-extensions: ^2.4
- laravel-doctrine/orm: ^1.2
- symfony/console: ~3.1
Requires (Dev)
- laravel/laravel: ^5.3
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^5.5
README
这是一个帮助将 Doctrine MongoDb ODM 集成到您选择的任何框架的包。目前唯一的限制是,通过定义缓存提供者,您正在声明您使用 Laravel。如果您使用其他框架,您将需要实现自己的缓存解决方案。
Laravel 配置
转到 config/app.php
并将服务提供者添加到您的 'providers'
部分: CImrie\Odm\OdmServiceProvider::class
发布配置文件: php artisan vendor:publish --tag=odm
现在您可以像这样使用默认的文档管理器
<?php use App\Http\Controllers\Controller; use Doctrine\ODM\MongoDB\DocumentManager; class IndexController extends Controller { public function index(DocumentManager $documentManager) { // code as normal ... $documentManager->flush(); // etc. } }
通用配置
此包针对 Laravel 设计,但为其他框架进行配置并非不可能,并且此包仍使手动配置 ODM 更加容易。
要生成文档管理器,您可以执行以下操作
<?php use CImrie\ODM\DocumentManagerFactory; use CImrie\ODM\Configuration\OdmConfigurationFactory; use CImrie\ODM\Configuration\Connections\ConnectionResolver; use CImrie\ODM\Configuration\MetaData\MetaDataRegistry; use \CImrie\ODM\Common\Registries\ListenerRegistry; use CImrie\ODM\Configuration\MetaData\Annotations; $connectionFactories = [ new \CImrie\ODM\Configuration\Connections\MongodbConnectionFactory() ]; $config = [ 'mongodb' => [ 'driver' => 'mongodb', 'host' => 'localhost', 'port' => 27017, 'database' => 'odm', 'username' => 'secretuser', 'password' => 'secretpass', 'options' => [ 'database' => 'admin', ], ] ]; $metaDataDrivers = [ new Annotations() ]; $dmFactory = new DocumentManagerFactory( new OdmConfigurationFactory(), new ConnectionResolver($connectionFactories, $config), new MetaDataRegistry([Annotations::class]), null, //cache manager new ListenerRegistry(), null //logger, which can be created by extending CImrie\ODM\Logging\Logger ); /* * <!------------- WARNING -------------!> */ //TODO - THIS PART OF THE DOCS IS NOT COMPLETE $dmFactory->create(new \CImrie\ODM\Common\Config( [ ], [ ], [ 'database' => [ 'connections' => [ ] ] ] ));