1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Migrations\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
6
|
|
|
use ProxyManager\Configuration; |
7
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
8
|
|
|
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; |
9
|
|
|
use ProxyManager\Proxy\LazyLoadingInterface; |
10
|
|
|
|
11
|
|
|
class LazySchemaDiffProvider implements SchemaDiffProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** @var LazyLoadingValueHolderFactory */ |
14
|
|
|
private $proxyFactory; |
15
|
|
|
|
16
|
|
|
/** @var SchemaDiffProviderInterface */ |
17
|
|
|
private $originalSchemaManipulator; |
18
|
|
|
|
19
|
114 |
|
public function __construct(LazyLoadingValueHolderFactory $proxyFactory, SchemaDiffProviderInterface $originalSchemaManipulator) |
20
|
|
|
{ |
21
|
114 |
|
$this->proxyFactory = $proxyFactory; |
22
|
114 |
|
$this->originalSchemaManipulator = $originalSchemaManipulator; |
23
|
114 |
|
} |
24
|
|
|
|
25
|
|
|
public static function fromDefaultProxyFacyoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator) |
26
|
|
|
{ |
27
|
|
|
$message = 'Function %s::fromDefaultProxyFacyoryConfiguration() deprecated due to typo.' |
28
|
|
|
. 'Use %s::fromDefaultProxyFactoryConfiguration() instead'; |
29
|
|
|
|
30
|
|
|
trigger_error( |
31
|
|
|
sprintf($message, self::class), |
32
|
|
|
E_USER_DEPRECATED |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
return self::fromDefaultProxyFactoryConfiguration($originalSchemaManipulator); |
36
|
|
|
} |
37
|
|
|
|
38
|
114 |
|
public static function fromDefaultProxyFactoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator) |
39
|
|
|
{ |
40
|
114 |
|
$proxyConfig = new Configuration(); |
41
|
114 |
|
$proxyConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); |
42
|
114 |
|
$proxyFactory = new LazyLoadingValueHolderFactory($proxyConfig); |
43
|
|
|
|
44
|
114 |
|
return new LazySchemaDiffProvider($proxyFactory, $originalSchemaManipulator); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return Schema |
49
|
|
|
*/ |
50
|
44 |
|
public function createFromSchema() |
51
|
|
|
{ |
52
|
44 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
53
|
|
|
|
54
|
44 |
|
return $this->proxyFactory->createProxy( |
55
|
44 |
|
Schema::class, |
56
|
44 |
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator) { |
57
|
13 |
|
$initializer = null; |
58
|
13 |
|
$wrappedObject = $originalSchemaManipulator->createFromSchema(); |
59
|
|
|
|
60
|
13 |
|
return true; |
61
|
44 |
|
} |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Schema $fromSchema |
67
|
|
|
* @return Schema |
68
|
|
|
*/ |
69
|
42 |
|
public function createToSchema(Schema $fromSchema) |
70
|
|
|
{ |
71
|
42 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
72
|
|
|
|
73
|
42 |
|
if ($fromSchema instanceof LazyLoadingInterface && ! $fromSchema->isProxyInitialized()) { |
74
|
41 |
|
return $this->proxyFactory->createProxy( |
75
|
41 |
|
Schema::class, |
76
|
41 |
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator, $fromSchema) { |
77
|
12 |
|
$initializer = null; |
78
|
12 |
|
$wrappedObject = $originalSchemaManipulator->createToSchema($fromSchema); |
79
|
|
|
|
80
|
12 |
|
return true; |
81
|
41 |
|
} |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
return $this->originalSchemaManipulator->createToSchema($fromSchema); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Schema $fromSchema |
90
|
|
|
* @param Schema $toSchema |
91
|
|
|
* |
92
|
|
|
* @return string[] |
93
|
|
|
*/ |
94
|
41 |
|
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema) |
95
|
|
|
{ |
96
|
41 |
|
if ($toSchema instanceof LazyLoadingInterface |
97
|
41 |
|
&& ! $toSchema->isProxyInitialized()) { |
98
|
33 |
|
return []; |
99
|
|
|
} |
100
|
|
|
|
101
|
13 |
|
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|