PHP code example of juliangut / doctrine-manager-builder
1. Go to this page and download the library: Download juliangut/doctrine-manager-builder 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' );
juliangut / doctrine-manager-builder example snippets
use Jgut \Doctrine \ManagerBuilder \ManagerBuilder ;
use Jgut \Doctrine \ManagerBuilder \RelationalBuilder ;
$rdbmsBuilder = new RelationalBuilder([
'annotation_autoloaders' => ['class_exists' ],
'connection' => [
'driver' => 'pdo_sqlite' ,
'memory' => true ,
],
'metadata_mapping' => [
[
'type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
'path' => 'path/to/entities' ,
],
],
]);
use Jgut \Doctrine \ManagerBuilder \ManagerBuilder ;
use Jgut \Doctrine \ManagerBuilder \MongoDBBuilder ;
$mongoDBBuilder = new MongoDBBuilder([
'annotation_autoloaders' => ['class_exists' ],
'connection' => [
'server' => 'mongodb://localhost:27017' ,
'options' => ['connect' => false ],
],
'metadata_mapping' => [
[
'driver' => new \Doctrine\ORM\Mapping\Driver\YamlDriver(
'path/to/document/yaml/mapping/files' ,
'.yml'
),
],
[
'type' => ManagerBuilder::METADATA_MAPPING_PHP,
'path' => 'path/to/document/php/mapping/files' ,
'namespace' => 'Project\Document\Namespace' ,
],
],
]);
$documentManager = $mongoDBBuilder->getManager();
use Jgut \Doctrine \ManagerBuilder \CouchDBBuilder ;
use Jgut \Doctrine \ManagerBuilder \MongoDBBuilder ;
$couchDBBuilder = new CouchDBBuilder([
'annotation_autoloaders' => ['class_exists' ],
'connection' => [
'host' => 'localhost' ,
'dbname' => 'doctrine' ,
],
'metadata_mapping' => [
[
'type' => ManagerBuilder::METADATA_MAPPING_XML,
'path' => 'path/to/document/xml/mapping/files' ,
'extension' => '.xml' ,
],
],
]);
$documentManager = $couchDBBuilder->getManager();
use Jgut \Doctrine \ManagerBuilder \RelationalBuilder ;
use Ramsey \Uuid \Doctrine \UuidType ;
'],
' connection' => [
' driver' => ' pdo_sqlite',
' memory' => true,
],
' metadata_mapping' => [
[
' type' => ManagerBuilder::METADATA_MAPPING_ANNOTATION,
' path' => ' path/to/entities',
],
],
// Register UUID as custom type
' custom_types' => [' uuid' => UuidType::class],
]);
$entityManager = $rdbmsBuilder->getManager();
use Gedmo \DoctrineExtensions ;
use Gedmo \Sluggable \SluggableListener ;
use Gedmo \SoftDeleteable \Filter \SoftDeleteableFilter ;
use Gedmo \SoftDeleteable \SoftDeleteableListener ;
use Gedmo \Timestampable \TimestampableListener ;
use Jgut \Doctrine \ManagerBuilder \RelationalBuilder ;
G_ANNOTATION,
'path' => 'path/to/entities' ,
],
],
'event_subscribers' => [
new SluggableListener,
new TimestampableListener,
new SoftDeleteableListener,
],
'custom_filters' => [
'soft-deleteable' => SoftDeleteableFilter::class,
],
]);
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($rdbmsBuilder->getMetadataMappingDriver());
$entityManager = $rdbmsBuilder->getManager();
use Jgut \Doctrine \ManagerBuilder \ConsoleBuilder ;
use Jgut \Doctrine \ManagerBuilder \RelationalBuilder ;
ilder->addBuilder(new RelationalBuilder($settings['main' ], 'one' ));
$consoleBuilder->addBuilder(new RelationalBuilder($settings['secondary' ], 'two' ));
return $consoleBuilder->getApplication();