Doctrine/ODM to Nette Framework.

# Content

# Setup

Install package

composer require nettrine/odm
1

Register extension

extensions:
  nettrine.odm: Nettrine\ODM\DI\OdmExtension
1
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 integration.

composer require nettrine/mongodb
1
extensions:
  nettrine.mongodb: Nettrine\MongoDB\DI\MongoDBExtension
1
2

Doctrine ODM needs MongoDB PHP Library 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 integration.

composer require nettrine/cache
1
extensions:
  nettrine.cache: Nettrine\Cache\DI\CacheExtension
1
2

Doctrine ODM needs Doctrine Cache 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
1
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
1
2
3

# symfony/console

This package relies on symfony/console, use prepared contributte/console integration.

composer require contributte/console
1
extensions:
  contributte.console: Contributte\Console\DI\ConsoleExtension(%consoleMode%)

  nettrine.odm: Nettrine\ODM\DI\OdmExtension
  nettrine.odm.console: Nettrine\ODM\DI\OdmConsoleExtension(%consoleMode%)
1
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
1
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[]>
1
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%
1
2
3

Side notes

  1. The compiler extensions would be so big that we decided to split them into more separate files / compiler extensions.

  2. 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
{
}
1
2
3
4
5
6

This feature relies on doctrine/annotations, use prepared nettrine/annotations integration.

composer require nettrine/annotations
1
extensions:
  nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension
1
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: []
1
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
1
2
3
4
5
6
7

# Other

This repository is inspired by these packages.

Thank you guys.

# Examples

You can find more examples in planette playground repository.