Factory used to create a new entity manager
This commit is contained in:
parent
37cb2c0722
commit
94adf97550
39
tests/Doctrine/Performance/EntityManagerFactory.php
Normal file
39
tests/Doctrine/Performance/EntityManagerFactory.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Performance;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Driver\PDOSqlite\Driver;
|
||||||
|
use Doctrine\ORM\Configuration;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Proxy\ProxyFactory;
|
||||||
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
|
||||||
|
final class EntityManagerFactory
|
||||||
|
{
|
||||||
|
public static function getEntityManager(array $schemaClassNames) : EntityManagerInterface
|
||||||
|
{
|
||||||
|
$config = new Configuration();
|
||||||
|
|
||||||
|
$config->setProxyDir(__DIR__ . '/../Tests/Proxies');
|
||||||
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||||
|
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
|
||||||
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([
|
||||||
|
realpath(__DIR__ . '/Models/Cache'),
|
||||||
|
realpath(__DIR__ . '/Models/GeoNames')
|
||||||
|
], true));
|
||||||
|
|
||||||
|
$entityManager = EntityManager::create(
|
||||||
|
[
|
||||||
|
'driverClass' => Driver::class,
|
||||||
|
'memory' => true,
|
||||||
|
],
|
||||||
|
$config
|
||||||
|
);
|
||||||
|
|
||||||
|
(new SchemaTool($entityManager))
|
||||||
|
->createSchema(array_map([$entityManager, 'getClassMetadata'], $schemaClassNames));
|
||||||
|
|
||||||
|
return $entityManager;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user