saxulum / saxulum-doctrine-mongodb-odm-manager-registry-provider
Doctrine MongoDB ODM Manager Registry Provider
Installs: 5 017
Dependents: 2
Suggesters: 2
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.9
- pimple/pimple: >=2.1,<4
- saxulum/saxulum-doctrine-mongodb-odm-provider: ~2.2,>=2.2.2
Requires (Dev)
- phpunit/phpunit: ~4.0
- saxulum/saxulum-console: ~3.0
- saxulum/saxulum-doctrine-mongodb-odm-commands: dev-master@dev
- silex/providers: ~2.0
- symfony/doctrine-bridge: ~2.3|~3.0
- symfony/form: ~2.3|~3.0
- symfony/validator: ~2.3|~3.0
Suggests
- saxulum/saxulum-console: ~3.0
- saxulum/saxulum-doctrine-mongodb-odm-commands: dev-master@dev
- silex/providers: ~2.0
- symfony/doctrine-bridge: ~2.3|~3.0
- symfony/form: ~2.3|~3.0
- symfony/validator: ~2.3|~3.0
README
Features
- Leverages the core Doctrine MongoDB Service Provider for either Silex or Cilex and the Doctrine MongoDB ODM Service Provider
- The Registry manager registry can the used with the Doctrine Bridge from symfony, to use document type in the Symfony Form Component
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();
...