saxulum/saxulum-doctrine-mongodb-odm-manager-registry-provider

Doctrine MongoDB ODM Manager Registry Provider

2.0.2 2017-10-26 08:47 UTC

README

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality

Features

Requirements

  • PHP 5.5+
  • Doctrine MongoDB ODM ~1.0

Currently requires both mongodbs and mongodbodm.dms services in order to work. These can be provided by a Doctrine MongoDB Service Provider and the Doctrine MongoDB ODM Service Provider service providers. If you can or want to fake it, go for it. :)

Installation

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

composer require "saxulum/saxulum-doctrine-mongodb-odm-manager-registry-provider": "dev-master@dev"
<?php

use Saxulum\DoctrineMongodbOdmManagerRegistry\Provider\DoctrineMongodbOdmManagerRegistryProvider;

$app->register(new DoctrineMongodbOdmManagerRegistryProvider());

Form Document Type

If you like to have Document Type Support within Symfony Form Component, install the Doctrine Bridge and register the form provider first.

{
    "require": {
        "symfony/doctrine-bridge": "~2.3|~3.0",
        "symfony/form": "~2.3|~3.0"
    }
}
<?php

use Saxulum\DoctrineMongodbOdmManagerRegistry\Provider\DoctrineMongodbOdmManagerRegistryProvider;
use Silex\Provider\FormServiceProvider;

$app->register(new FormServiceProvider());
$app->register(new DoctrineMongodbOdmManagerRegistryProvider());

Validator

If you like to have Unique Constraint Support within Symfony Validator Component, install the Doctrine Bridge and register the validator provider first.

{
    "require": {
        "symfony/doctrine-bridge": "~2.3|~3.0",
        "symfony/validator": "~2.3|~3.0"
    }
}
<?php

use Saxulum\DoctrineMongodbOdmManagerRegistry\Provider\DoctrineMongodbOdmManagerRegistryProvider;
use Silex\Provider\ValidatorServiceProvider;

$app->register(new ValidatorServiceProvider());
$app->register(new DoctrineMongodbOdmManagerRegistryProvider());
<?php

use Doctrine\ORM\Mapping as ORM;
use Saxulum\DoctrineMongodbOdmManagerRegistry\Validator\Constraints\Unique;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
 * @ORM\Document()
 * @ORM\Table(name="sample")
 */
class Sample
{
    /**
     * @var string
     * @ORM\Column(name="name", type="string")
     */
    protected $name;

    /**
     * @param ClassMetadata $metadata
     */
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addConstraint(new Unique(array(
            'fields'  => 'name',
            'message' => 'This name already exists.',
        )));
    }
}

Symfony Console

If you like to use Doctrine MongoDB ODM Commands, install Doctrine MongoDB ODM Commands and the Saxulum Console Provider and register the console provider.

{
    "require": {
        "saxulum/saxulum-doctrine-mongodb-odm-commands": "dev-master@dev",
        "saxulum/saxulum-console": "~2.3|~3.0",
    }
}
<?php

use Saxulum\DoctrineMongodbOdmManagerRegistry\Provider\DoctrineMongodbOdmManagerRegistryProvider;
use Saxulum\Console\Provider\ConsoleProvider;

$app->register(new ConsoleProvider());
$app->register(new DoctrineMongodbOdmManagerRegistryProvider());

Usage

<?php

// get the default connection name
$app['doctrine_mongodb']->getDefaultConnectionName();

// get the default connection
$app['doctrine_mongodb']->getConnection();

// get a connection by name
$app['doctrine_mongodb']->getConnection('name');

// all connections as array access (pimple)
$app['doctrine_mongodb']->getConnections();

// all connection names as array
$app['doctrine_mongodb']->getConnectionNames();

// get the default manager name
$app['doctrine_mongodb']->getDefaultManagerName();

// get the default manager
$app['doctrine_mongodb']->getManager();

// get a manager by name
$app['doctrine_mongodb']->getManager('name');

// all manager as array access (pimple)
$app['doctrine_mongodb']->getManagers();

// all manager names as array
$app['doctrine_mongodb']->getManagerNames();
...