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

1. Go to this page and download the library: Download saxulum/saxulum-doctrine-mongodb-odm-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-provider example snippets




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



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'    
                ]    
            ]
        ],
    ],
]);

   
   $app['mongodbodm.dms.default'] = 'sqlite';
   $app['mongodbodm.dms.options'] = [
        'mongo1' => [
            'server' => 'mongodb://localhost:27017',
            'options' => [
                'username' => 'root',
                'password' => 'root',
                'db' => 'admin'
            ]
        ],
        'mongo2' => [
            'server' => 'mongodb://localhost:27018',
            'options' => [
                'username' => 'root',
                'password' => 'root',
                'db' => 'admin'
            ]
        ]
   ];
   

   
   $emMysql = $app['mongodbodm.dms']['mongo1'];
   $emSqlite = $app['mongodbodm.dms']['mongo2'];
   

   
   $emName = $app['mongodbodm.dm_name_from_param']('3rdparty.provider.dm');
   $em = $app['mongodbodm.dms'][$emName];
   


$loader = on\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);