2017 © Pedro Peláez
 

library droctrine-mongo

Adds Doctrine MongoDB ODM Services to Drimple for use in Drupal 7.x.

image

korstiaan/droctrine-mongo

Adds Doctrine MongoDB ODM Services to Drimple for use in Drupal 7.x.

  • Wednesday, September 5, 2012
  • by korstiaan
  • Repository
  • 0 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Droctrine Mongo for Drupal 7.x

Adds Doctrine MongoDB ODM Services to Drimple for use in Drupal 7.x., (*1)

Build Status, (*2)

Requirements

Installation

The recommended way to install Droctrine Mongo is with Composer. Just add the following to your composer.json:, (*3)

   {
       "minimum-stability": "dev",
       "require": {
              ...
           "korstiaan/droctrine-mongo": "dev-master"
       }
   }

Now update composer and install the newly added requirement and its dependencies (including Drimple):, (*4)

``` bash $ php composer.phar update korstiaan/droctrine-mongo, (*5)


### Using Composer Using `Composer` means including its autoloader. Add the following to your Drupals settings.php: ```php // /path/to/sites/default/settings.php require '/path/to/vendor/autoload.php';

Configuration

Implement hook_hook_drimple_provide(\Drimple\Drimple $drimple) and register the service provider. For example:, (*6)

<?php
// sites/all/modules/foo/foo.module

function foo_drimple_provide(\Drimple\Drimple $drimple)
{
    $drimple->register(
        new \Droctrine\Mongo\Provider\DoctrineMongoDBProvider(), 
        array(
            'doctrine.odm.mongodb.config.connection' => array(
                'connections' => array(
                    'default' => array(
                        'server'  =>  'mongodb://localhost:27017',
                        'options' => array(
                            'connect' => true,
                        ),
                    ),
                ),
                'default' => 'default',
            ),
            'doctrine.odm.mongodb.config.manager' => array(
                'managers' => array(
                    'default' => array(
                        'auto_mapping' => true,
                    ),
                ),
                'config'   => array(
                    'proxy_dir'    => file_directory_temp(),
                    'hydrator_dir' => file_directory_temp(),
                    'database'     => 'db_mongo',
                ),
                'default' => 'default',
            ),
        )
    );
}

Effectively, this will add the document manager for the default manager with default connection into the doctrine.odm.mongodb.dm service., (*7)

See `DoctrineMongoDBProvider::loadDocumentManagers` and `DoctrineMongoDBProvider::loadConnections` phpdocs for more configuration information and the other services it defines

Usage

When setting auto_mapping = true in the provider's configuration, documents are looked for in every module's subdir ModuleName/Document with namespace ModuleName\Document. (Base namespace of a module is based on an underscore to CamelCase conversion), (*8)

<?php
// sites/all/modules/foo_bar/FooBar/Document/User.php

namespace FooBar\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class User
{
    /**
     * @MongoDB\Id
     */
    protected $id;
}

Now if you want to persist this document, just:, (*9)


$dm = drimple()->get('doctrine.odm.mongodb.dm'); $user = new \FooBar\Document\User(); $dm->persist($user); $dm->flush();

Or if you want to fetch all documents:, (*10)


$dm = drimple()->get('doctrine.odm.mongodb.dm'); $docs = $dm->getRepository('FooBar\\Document\\User')->findAll();

Limitations

  • For now only the annotation driver is supported.

License

Droctrine Mongo is licensed under the MIT license., (*11)

The Versions

05/09 2012

dev-master

9999999-dev http://korstiaan.com/droctrine-mongo

Adds Doctrine MongoDB ODM Services to Drimple for use in Drupal 7.x.

  Sources   Download

MIT

The Requires

 

The Development Requires

mongodb doctrine drupal odm