helderjs / doctrine-mongo-odm
DoctrineMongoODM component for (Micro-)Framework
Installs: 18 067
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 5
Open Issues: 3
Requires
- php: ~5.6 || >=7.0
- doctrine/mongodb-odm: ^1.1
- psr/container: ^1.0
Requires (Dev)
- alcaeus/mongo-php-adapter: ^1.0
- phpunit/phpunit: ^4.8 || ^5.7
- squizlabs/php_codesniffer: ^2.7
This package is not auto-updated.
Last update: 2025-03-21 19:53:12 UTC
README
It's a component based on DoctrineMongoODMModule that provides DoctrineMongoDbODM integration for several (Micro-)frameworks. The goal is be light and easy to configure, for that the library rely just on the PSR-11 and MongoBD ODM.
Requirements
- PHP 5.6+
- ext-mongo (if php version < 7)
- mongo-php-adapter (if php version >= 7)
ps.: if using mongo-php-adapter you should add and install it first in you project. After this the library will declare to composer that it provides the ext-mongo.
We recommend using a dependency injection container, and typehint against PSR-11.
Installation
Install this library using composer:
$ composer require helderjs/doctrine-mongo-odm
Configuration
How to create the config file (What you should/can put in the config).
return [ 'config' => [ ... 'doctrine' => [ 'default' => 'odm_default', 'connection' => [ 'odm_default' => [ 'server' => 'localhost', 'port' => '27017', 'user' => 'myUser', 'password' => 'myHardPassword', 'dbname' => 'dbName', 'options' => [] ], 'odm_secondary' => [ 'connectionString' => 'mongodb://username:password@server2:27017/mydb', 'options' => [] ], ], 'driver' => [ 'odm_default' => [ \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::class => [ 'documents_dir' => ['./src/myApp/Documents'] ], \Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver::class => [ 'simplified' => false, 'xml_dir' => [ '/path/to/files1', '/path/to/files2', ] ], \Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver::class => [ 'simplified' => false, 'yml_dir' => [ '/path/to/files1', '/path/to/files2', ] ], \Doctrine\ODM\MongoDB\Mapping\Driver\MappingDriverChain::class => [ 'Driver\Annotation' => \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::class, 'Driver\Xml' => \Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver::class, 'Driver\Yaml' => \Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver::class, ], ], ], 'configuration' => [ 'odm_default' => [ 'metadata_cache' => \Doctrine\Common\Cache\ArrayCache::class, // optional 'driver' => \Doctrine\ODM\MongoDB\Mapping\Driver\MappingDriverChain::class, 'generate_proxies' => true, 'proxy_dir' => 'data/DoctrineMongoODMModule/Proxy', 'proxy_namespace' => 'DoctrineMongoODMModule\Proxy', 'generate_hydrators' => true, 'hydrator_dir' => 'data/DoctrineMongoODMModule/Hydrator', 'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator', 'default_db' => 'MyDBName', 'filters' => [], // custom filters (optional) 'types' => [], // custom types (optional) 'retry_connect' => 0 // optional 'retry_query' => 0 // optional 'logger' => \MyLogger::calss \\ Logger implementation (optional) 'classMetadataFactoryName' => 'stdClass' \\ optional ] ], 'documentmanager' => [ 'odm_default' => [ 'connection' => \Doctrine\ODM\MongoDB\Connection::class, 'configuration' => \Doctrine\ODM\MongoDB\Configuration::class, 'eventmanager' => \Doctrine\ODM\MongoDB\EventManager::class, \\ optional ], 'odm_secondary' => [ 'connection' => 'doctrine.connection.secondary', 'configuration' => \Doctrine\ODM\MongoDB\Configuration::class, 'eventmanager' => 'doctrine.eventmanager.secondary', \\ optional ] ], 'eventmanager' => [ \\ optional 'odm_default' => [ 'subscribers' => [ \MySubscriberImpl1::class, ], ], 'odm_secondary' => [ 'subscribers' => [ new \MySubscriberImpl2(), ], ], ], ], ... ], ];
Configuring DI at Zend Expressive
... 'dependencies' => [ 'invokables' => [ \Doctrine\Common\Cache\ArrayCache::class => \Doctrine\Common\Cache\ArrayCache::class, \MyLogger::class => \MyLogger::class, ], 'factories' => [ \Doctrine\ODM\MongoDB\Configuration::class => ConfigurationFactory::class, \Doctrine\ODM\MongoDB\Connection::class => ConnectionFactory::class, \Doctrine\ODM\MongoDB\EventManager::class => EventManagerFactory::class, \Doctrine\ODM\MongoDB\DocumentManager::class => DocumentManagerFactory::class, 'doctrine.connection.secondary' => new ConnectionFactory('odm_secondary'), 'doctrine.eventmanager.secondary' => new EventManagerFactory('odm_secondary'), 'doctrine.documentmandager.secondary' => new DocumentManagerFactory('odm_secondary'), \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::class => \Helderjs\Component\DoctrineMongoODM\AnnotationDriverFactory::class, \Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver::class => \Helderjs\Component\DoctrineMongoODM\AnnotationDriverFactory::class, \Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver::class => \Helderjs\Component\DoctrineMongoODM\AnnotationDriverFactory::class, \Doctrine\ODM\MongoDB\Mapping\Driver\MappingDriverChain::class => \Helderjs\Component\DoctrineMongoODM\AnnotationDriverFactory::class, ], ], ...
SlimPHP
$container['doctrine-connection'] = function ($container) { $factory = new ConnectionFactory(); return $factory($container); }; $container['doctrine-configuration'] = function ($container) { $factory = new ConfigurationFactory(); return $factory($container); }; $container['doctrine-eventmanager'] = function ($container) { $factory = new EventManagerFactory(); return $factory($container); }; $container['doctrine-driver'] = function ($container) { $factory = new MappingDriverChainFactory(); return $factory($container); };
Goals
- Improve unit tests
- Improve documentation
- Implementing real examples
- ?introduce new features?
If you want to help: install, test it, report an issue, fork, open a pull request
License
The MIT License (MIT). Please see License File for more information.