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