Coder Social home page Coder Social logo

doctrine-mongo-odm's Introduction

DoctrineMongoODM Component

Build Status

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

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.

doctrine-mongo-odm's People

Contributors

helderjs avatar matwright avatar vinaocruz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

doctrine-mongo-odm's Issues

How to use Redis as cache backend?

Hello,

First thank for this cool project!

I'm wondering how I can configure Redis as a cache backend, do you have a way to do that right now or should we think about it and maybe push a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.