PHP code example of mi-la01 / doctrine-orm-service-provider

1. Go to this page and download the library: Download mi-la01/doctrine-orm-service-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/ */

    

mi-la01 / doctrine-orm-service-provider example snippets




// Default entity manager.
$em = $app['orm.em'];



use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
use Pimple\Container;

$container = new Container;

$container['db.options'] = array(
    'driver' => 'pdo_sqlite',
    'path' => '/path/to/sqlite.db',
);

// ensure that $container['dbs'] and $container['dbs.event_manager']
// are available, most likely by way of a core service provider.

$container->register(new DoctrineOrmServiceProvider, array(
    'orm.proxies_dir' => '/path/to/proxies',
    'orm.em.options' => array(
        'mappings' => array(
            // Using actual filesystem paths
            array(
                'type' => 'annotation',
                'namespace' => 'Foo\Entities',
                'path' => __DIR__.'/src/Foo/Entities',
            ),
            array(
                'type' => 'xml',
                'namespace' => 'Bat\Entities',
                'path' => __DIR__.'/src/Bat/Resources/mappings',
            ),
            // XML/YAML driver (Symfony2 style)
            // Mapping files can be named like Foo.orm.yml
            // instead of Baz.Entities.Foo.dcm.yml
            array(
                'type' => 'simple_yml',
                'namespace' => 'Baz\Entities',
                'path' => __DIR__.'/src/Bat/Resources/config/doctrine',
            ),
        ),
    ),
));



use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
use Silex\Application;
use Silex\Provider\DoctrineServiceProvider;

$app = new Application;

$app->register(new DoctrineServiceProvider, array(
    'db.options' => array(
        'driver' => 'pdo_sqlite',
        'path' => '/path/to/sqlite.db',
    ),
));

$app->register(new DoctrineOrmServiceProvider, array(
    'orm.proxies_dir' => '/path/to/proxies',
    'orm.em.options' => array(
        'mappings' => array(
            // Using actual filesystem paths
            array(
                'type' => 'annotation',
                'namespace' => 'Foo\Entities',
                'path' => __DIR__.'/src/Foo/Entities',
            ),
            array(
                'type' => 'xml',
                'namespace' => 'Bat\Entities',
                'path' => __DIR__.'/src/Bat/Resources/mappings',
            ),
        ),
    ),
));

   
   $app['orm.ems.default'] = 'sqlite';
   $app['orm.ems.options'] = array(
       'mysql' => array(
           'connection' => 'mysql',
           'mappings' => array(), 
       ),
       'sqlite' => array(
           'connection' => 'sqlite',
           'mappings' => array(),
       ),
   );
   

   
   $emMysql = $app['orm.ems']['mysql'];
   $emSqlite = $app['orm.ems']['sqlite'];
   

   
   $emName = $app['orm.em_name_from_param']('3rdparty.provider.em');
   $em = $app['orm.ems'][$emName];
   


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