|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Migrations\Provider; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
use ProxyManager\Configuration; |
|
9
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
|
10
|
|
|
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; |
|
11
|
|
|
use ProxyManager\Proxy\LazyLoadingInterface; |
|
12
|
|
|
|
|
13
|
|
|
class LazySchemaDiffProvider implements SchemaDiffProviderInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var LazyLoadingValueHolderFactory */ |
|
16
|
|
|
private $proxyFactory; |
|
17
|
|
|
|
|
18
|
|
|
/** @var SchemaDiffProviderInterface */ |
|
19
|
|
|
private $originalSchemaManipulator; |
|
20
|
|
|
|
|
21
|
121 |
|
public function __construct( |
|
22
|
|
|
LazyLoadingValueHolderFactory $proxyFactory, |
|
23
|
|
|
SchemaDiffProviderInterface $originalSchemaManipulator |
|
24
|
|
|
) { |
|
25
|
121 |
|
$this->proxyFactory = $proxyFactory; |
|
26
|
121 |
|
$this->originalSchemaManipulator = $originalSchemaManipulator; |
|
27
|
121 |
|
} |
|
28
|
|
|
|
|
29
|
121 |
|
public static function fromDefaultProxyFactoryConfiguration( |
|
30
|
|
|
SchemaDiffProviderInterface $originalSchemaManipulator |
|
31
|
|
|
) : LazySchemaDiffProvider { |
|
32
|
121 |
|
$proxyConfig = new Configuration(); |
|
33
|
121 |
|
$proxyConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); |
|
34
|
121 |
|
$proxyFactory = new LazyLoadingValueHolderFactory($proxyConfig); |
|
35
|
|
|
|
|
36
|
121 |
|
return new LazySchemaDiffProvider($proxyFactory, $originalSchemaManipulator); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
49 |
|
public function createFromSchema() : Schema |
|
40
|
|
|
{ |
|
41
|
49 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
|
42
|
|
|
|
|
43
|
49 |
|
return $this->proxyFactory->createProxy( |
|
|
|
|
|
|
44
|
49 |
|
Schema::class, |
|
45
|
|
|
function (&$wrappedObject, $proxy, $method, array $parameters, &$initializer) use ($originalSchemaManipulator) { |
|
46
|
13 |
|
$initializer = null; |
|
47
|
13 |
|
$wrappedObject = $originalSchemaManipulator->createFromSchema(); |
|
48
|
|
|
|
|
49
|
13 |
|
return true; |
|
50
|
49 |
|
} |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
47 |
|
public function createToSchema(Schema $fromSchema) : Schema |
|
55
|
|
|
{ |
|
56
|
47 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
|
57
|
|
|
|
|
58
|
47 |
|
if ($fromSchema instanceof LazyLoadingInterface && ! $fromSchema->isProxyInitialized()) { |
|
59
|
46 |
|
return $this->proxyFactory->createProxy( |
|
|
|
|
|
|
60
|
46 |
|
Schema::class, |
|
61
|
|
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator, $fromSchema) { |
|
62
|
12 |
|
$initializer = null; |
|
63
|
12 |
|
$wrappedObject = $originalSchemaManipulator->createToSchema($fromSchema); |
|
64
|
|
|
|
|
65
|
12 |
|
return true; |
|
66
|
46 |
|
} |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
return $this->originalSchemaManipulator->createToSchema($fromSchema); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** @return string[] */ |
|
74
|
46 |
|
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema) : array |
|
75
|
|
|
{ |
|
76
|
46 |
|
if ($toSchema instanceof LazyLoadingInterface |
|
77
|
46 |
|
&& ! $toSchema->isProxyInitialized()) { |
|
78
|
38 |
|
return []; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
13 |
|
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|