|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Performance; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\EventManager; |
|
8
|
|
|
use Doctrine\DBAL\Cache\ArrayStatement; |
|
9
|
|
|
use Doctrine\DBAL\Cache\QueryCacheProfile; |
|
10
|
|
|
use Doctrine\DBAL\Connection; |
|
11
|
|
|
use Doctrine\DBAL\Driver\PDOSqlite\Driver; |
|
12
|
|
|
use Doctrine\ORM\Configuration; |
|
13
|
|
|
use Doctrine\ORM\EntityManager; |
|
14
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
15
|
|
|
use Doctrine\ORM\Proxy\ProxyFactory; |
|
16
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
|
17
|
|
|
use function array_map; |
|
18
|
|
|
use function realpath; |
|
19
|
|
|
|
|
20
|
|
|
final class EntityManagerFactory |
|
21
|
|
|
{ |
|
22
|
|
|
public static function getEntityManager(array $schemaClassNames) : EntityManagerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
$config = new Configuration(); |
|
25
|
|
|
|
|
26
|
|
|
$config->setProxyDir(__DIR__ . '/../Tests/Proxies'); |
|
27
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies'); |
|
28
|
|
|
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); |
|
29
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ |
|
30
|
|
|
realpath(__DIR__ . '/Models/Cache'), |
|
31
|
|
|
realpath(__DIR__ . '/Models/GeoNames'), |
|
32
|
|
|
], true)); |
|
33
|
|
|
|
|
34
|
|
|
$entityManager = EntityManager::create( |
|
35
|
|
|
[ |
|
36
|
|
|
'driverClass' => Driver::class, |
|
37
|
|
|
'memory' => true, |
|
38
|
|
|
], |
|
39
|
|
|
$config |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
(new SchemaTool($entityManager)) |
|
43
|
|
|
->createSchema(array_map([$entityManager, 'getClassMetadata'], $schemaClassNames)); |
|
44
|
|
|
|
|
45
|
|
|
return $entityManager; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public static function makeEntityManagerWithNoResultsConnection() : EntityManagerInterface |
|
49
|
|
|
{ |
|
50
|
|
|
$config = new Configuration(); |
|
51
|
|
|
|
|
52
|
|
|
$config->setProxyDir(__DIR__ . '/../Tests/Proxies'); |
|
53
|
|
|
$config->setProxyNamespace('Doctrine\Tests\Proxies'); |
|
54
|
|
|
$config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); |
|
55
|
|
|
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ |
|
56
|
|
|
realpath(__DIR__ . '/Models/Cache'), |
|
57
|
|
|
realpath(__DIR__ . '/Models/Generic'), |
|
58
|
|
|
realpath(__DIR__ . '/Models/GeoNames'), |
|
59
|
|
|
], true)); |
|
60
|
|
|
|
|
61
|
|
|
// A connection that doesn't really do anything |
|
62
|
|
|
$connection = new class ([], new Driver(), null, new EventManager()) extends Connection |
|
63
|
|
|
{ |
|
64
|
|
|
/** {@inheritdoc} */ |
|
65
|
|
|
public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) |
|
66
|
|
|
{ |
|
67
|
|
|
return new ArrayStatement([]); |
|
68
|
|
|
} |
|
69
|
|
|
}; |
|
70
|
|
|
|
|
71
|
|
|
return EntityManager::create($connection, $config); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|