Contributte Doctrine-odm
Doctrine/ODM (opens new window) to Nette Framework.
# Content
# Setup
Register extension
extensions:
nettrine.odm: Nettrine\ODM\DI\OdmExtension
2
# Relying
Take advantage of enpowering this package with 3 extra packages:
mongodb/mongodb
doctrine/cache
symfony/console
# mongodb/mongodb
This package relies on mongodb/mongodb
, use prepared nettrine/mongodb (opens new window) integration.
composer require nettrine/mongodb
extensions:
nettrine.mongodb: Nettrine\MongoDB\DI\MongoDBExtension
2
Doctrine ODM (opens new window) needs MongoDB PHP Library (opens new window) to be configured. If you register nettrine/mongodb
extension it will detect it automatically.
MongoDB PHP Library provides a high-level abstraction around the lower-level PHP driver (mongodb extension).
# doctrine/cache
This package relies on doctrine/cache
, use prepared nettrine/cache (opens new window) integration.
composer require nettrine/cache
extensions:
nettrine.cache: Nettrine\Cache\DI\CacheExtension
2
Doctrine ODM (opens new window) needs Doctrine Cache (opens new window) to be configured. If you register nettrine/cache
extension it will detect it automatically.
CacheExtension
sets up cache for all important parts: metadataCache
.
This is the default configuration, it uses the autowired driver.
extensions:
nettrine.odm: Nettrine\ODM\DI\OdmExtension
nettrine.odm.cache: Nettrine\ODM\DI\OdmCacheExtension
2
3
You can also specify a single driver or change the nettrine.odm.cache.defaultDriver
for specific ones.
nettrine.odm.cache:
defaultDriver: App\DefaultOdmCacheDriver
metadataCache: @cacheDriver
2
3
# symfony/console
This package relies on symfony/console
, use prepared contributte/console (opens new window) integration.
composer require contributte/console
extensions:
contributte.console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)
nettrine.odm: Nettrine\ODM\DI\OdmExtension
nettrine.odm.console: Nettrine\ODM\DI\OdmConsoleExtension(%consoleMode%)
2
3
4
5
Since this moment when you type bin/console
, there'll be registered commands from Doctrine DBAL.
odm
odm:clear-cache:metadata Clear all metadata cache of the various cache drivers.
odm:generate:hydrators Generates hydrator classes for document classes.
odm:generate:proxies Generates proxy classes for document classes.
odm:query Query mongodb and inspect the outputted results from your document classes.
odm:schema:create Create databases, collections and indexes for your documents
odm:schema:drop Drop databases, collections and indexes for your documents
odm:schema:update Update indexes for your documents
2
3
4
5
6
7
8
# Configuration
Schema definition
nettrine.odm:
configurationClass: <class>
configuration:
autoGenerateProxyClasses: <boolean>
defaultDB: <string>
proxyDir: <path>
proxyNamespace: <string>
hydratorDir: <path>
hydratorNamespace: <string>
metadataDriverImpl: <service>
classMetadataFactoryName: <string>
repositoryFactory: <class>
types: <class[]>
2
3
4
5
6
7
8
9
10
11
12
13
14
Under the hood
Minimal configuration could look like this:
nettrine.odm:
configuration:
autoGenerateProxyClasses: %debugMode%
2
3
Side notes
The compiler extensions would be so big that we decided to split them into more separate files / compiler extensions.
At this time we support only 1 connection, the default connection. If you need more connections (more databases?), please open an issue or send a PR. Thanks.
# Mapping
Doctrine ODM needs to know where your entities are located and how they are described (mapping).
Additional metadata provider needs to be registered. We provide bridges for these drivers:
- annotations (
Nettrine\ODM\DI\OdmAnnotationsExtension
) - xml (
Nettrine\ODM\DI\OdmXmlExtension
)
# Annotations
Are you using annotations in your entities?
/**
* @ODM\Document
*/
class Article
{
}
2
3
4
5
6
This feature relies on doctrine/annotations
, use prepared nettrine/annotations (opens new window) integration.
composer require nettrine/annotations
extensions:
nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension
2
You will also appreciate ODM => Annotations bridge, use OdmAnnotationsExtension
. This is the default configuration, it uses an autowired cache driver.
extensions:
nettrine.odm: Nettrine\ODM\DI\OdmExtension
nettrine.odm.annotations: Nettrine\ODM\DI\OdmAnnotationsExtension
nettrine.odm.annotations:
paths: []
excludePaths: []
2
3
4
5
6
7
# XML
Are you using XML mapping for your entities?
You will also appreciate ODM => XML bridge, use OdmXmlExtension
. This is the default configuration:
extensions:
nettrine.odm: Nettrine\ODM\DI\OdmExtension
nettrine.odm.xml: Nettrine\ODM\DI\OdmXmlExtension
nettrine.odm.xml:
paths: []
fileExtension: .dcm.xml
2
3
4
5
6
7
# Other
This repository is inspired by these packages.
Thank you guys.
# Examples
- https://github.com/contributte/playground (opens new window) (playground)
- https://contributte.org/examples.html (opens new window) (more examples)