Esempio n. 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;
 }
 protected function loadMetadata($name)
 {
     $origName = $name;
     if ($this->config instanceof Kdyby\Doctrine\Configuration) {
         $name = $this->config->getTargetEntityClassName($name);
     }
     if (!class_exists($name)) {
         throw new Kdyby\Doctrine\MissingClassException("Metadata of class {$name} was not found, because the class is missing or cannot be autoloaded.");
     }
     $result = parent::loadMetadata($name);
     if ($name !== $origName) {
         $this->setMetadataFor($origName, $this->getMetadataFor($name));
     }
     return $result;
 }
 /**
  * @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;
 }