saxulum-legacy / saxulum-doctrine-mongodb-odm-provider

A simple mongodb odm service provider for pimple, silex, cilex
MIT License
10 stars 3 forks source link

saxulum-doctrine-mongodb-odm-provider

works with plain silex-php

Build Status Total Downloads Latest Stable Version

Provides Doctrine MongoDB ODM Document Managers as services to Pimple applications.

Features

Requirements

Installation

Through Composer as saxulum/saxulum-doctrine-mongodb-odm-provider.

Usage

To get up and running, register DoctrineMongoDbOdmProvider and manually specify the directory that will contain the proxies along with at least one mapping.

In each of these examples an Document Manager that is bound to the default database connection will be provided. It will be accessible via mongodbodm.dm.

<?php

// Default document manager.
$em = $app['mongodbodm.dm'];

Pimple

<?php

use Pimple\Container;
use Saxulum\DoctrineMongoDb\Provider\DoctrineMongoDbProvider;
use Saxulum\DoctrineMongoDbOdm\Provider\DoctrineMongoDbOdmProvider;

$app = new Container;

$app->register(new DoctrineMongoDbProvider, [
    "mongodb.options" => [
        "server" => "mongodb://localhost:27017",
        "options" => [
            "username" => "root",
            "password" => "root",
            "db" => "admin"
        ],
    ],
]);

$app->register(new DoctrineMongoDbOdmProvider, [
    "mongodbodm.proxies_dir" => "/path/to/proxies",
    "mongodbodm.hydrator_dir" => "/path/to/hydrator",
    "mongodbodm.dm.options" => [
        "database" => "test",
        "mappings" => [
            // Using actual filesystem paths
            [
                "type" => "annotation",
                "namespace" => "Foo\Entities",
                "path" => __DIR__."/src/Foo/Entities",
            ],
            [
                "type" => "xml",
                "namespace" => "Bat\Entities",
                "path" => __DIR__."/src/Bat/Resources/mappings",
            ],
            [
                'type' => 'class_map',
                'namespace' => 'Bar\Entities',
                'map' => [
                    'Bar\Entities\Bar' => 'Sample\Mapping\Bar'    
                ]    
            ]
        ],
    ],
]);

Configuration

Parameters

Services

Frequently Asked Questions

Why aren't my Annotations classes being found?

When use_simple_annotation_reader is set to False for an document, the AnnotationRegistry needs to have the project's autoloader added to it.

Example:

<?php
$loader = require __DIR__ . '/../vendor/autoload.php';

\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);

License

MIT, see LICENSE.

Community

If you have questions or want to help out, join us in the #silex-php channels on irc.freenode.net.

Not Invented Here

This project is based heavily on the work done by @dflydev on the dflydev/dflydev-doctrine-orm-service-provider project.

Copyright