PHP code example of saxulum / saxulum-doctrine-mongodb-odm-manager-registry-provider

1. Go to this page and download the library: Download saxulum/saxulum-doctrine-mongodb-odm-manager-registry-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

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

{.php}


use Saxulum\DoctrineMongodbOdmManagerRegistry\Provider\DoctrineMongodbOdmManagerRegistryProvider;

$app->register(new DoctrineMongodbOdmManagerRegistryProvider());
{.php}


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

$app->register(new FormServiceProvider());
$app->register(new DoctrineMongodbOdmManagerRegistryProvider());
{.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.',
        )));
    }
}
{.php}


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

$app->register(new ConsoleProvider());
$app->register(new DoctrineMongodbOdmManagerRegistryProvider());
{.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();
...