create() 공개 정적인 메소드

Factory method to create EntityManager instances.
public static create ( Doctrine\DBAL\Connection | array $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager = NULL ) : EntityManager
$conn Doctrine\DBAL\Connection | array
$config Doctrine\ORM\Configuration
$eventManager Doctrine\Common\EventManager
리턴 EntityManager
예제 #1
0
 /**
  * @return Kdyby\Doctrine\EntityManager
  */
 protected function createMemoryManager($classNames = NULL, $createSchema = TRUE)
 {
     $conf = ['driver' => 'pdo_sqlite', 'memory' => TRUE];
     $connection = new Kdyby\Doctrine\Connection($conf, new Driver());
     $config = new Kdyby\Doctrine\Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(TEMP_DIR);
     $config->setProxyNamespace('TestProxy');
     $config->setDefaultRepositoryClassName('Kdyby\\Doctrine\\EntityRepository');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__ . '/Model/', VENDOR_DIR], FALSE));
     $em = Kdyby\Doctrine\EntityManager::create($connection, $config);
     $em->getEventManager()->addEventSubscriber(new SortableListener());
     if ($createSchema === FALSE) {
         return $em;
     }
     $schemaTool = new SchemaTool($em);
     if ($classNames !== NULL) {
         $meta = [];
         foreach ((array) $classNames as $className) {
             $meta[] = $em->getClassMetadata($className);
         }
     } else {
         $meta = $em->getMetadataFactory()->getAllMetadata();
     }
     $schemaTool->createSchema($meta);
     return $em;
 }
예제 #2
0
 protected function setUp()
 {
     $config = new \Kdyby\Doctrine\Configuration();
     $mapping = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new \Doctrine\Common\Annotations\AnnotationReader(), [__DIR__ . '/entitites']);
     $config->setMetadataDriverImpl($mapping);
     $config->setProxyDir(__DIR__ . '/proxy');
     $config->setProxyNamespace('Tests\\_ProxyTests');
     \Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     $event = new \Doctrine\Common\EventManager();
     $conn = new \Kdyby\Doctrine\Connection(array('dbname' => 'test', 'user' => 'travis', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql'), new \Doctrine\DBAL\Driver\PDOMySql\Driver(), $config, $event);
     $em = \Kdyby\Doctrine\EntityManager::create($conn, $config, $event);
     $this->helper = new \WebChemistry\Forms\Doctrine($em);
 }
 /**
  * @return Kdyby\Doctrine\EntityManager
  */
 protected function createMemoryManager($createSchema = TRUE)
 {
     $conf = ['driver' => 'pdo_sqlite', 'memory' => TRUE];
     $connection = new Kdyby\Doctrine\Connection($conf, new Driver());
     $config = new Kdyby\Doctrine\Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(TEMP_DIR);
     $config->setProxyNamespace('TestProxy');
     $config->setDefaultRepositoryClassName(Kdyby\Doctrine\EntityDao::class);
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__], FALSE));
     $em = Kdyby\Doctrine\EntityManager::create($connection, $config);
     if ($createSchema === FALSE) {
         return $em;
     }
     $schemaTool = new SchemaTool($em);
     $meta = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool->createSchema($meta);
     return $em;
 }