1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Migrations\Provider; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Schema\Schema; |
23
|
|
|
use ProxyManager\Configuration; |
24
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
25
|
|
|
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; |
26
|
|
|
use ProxyManager\Proxy\LazyLoadingInterface; |
27
|
|
|
|
28
|
|
|
class LazySchemaDiffProvider implements SchemaDiffProviderInterface |
29
|
|
|
{ |
30
|
|
|
/** @var LazyLoadingValueHolderFactory */ |
31
|
|
|
private $proxyFactory; |
32
|
|
|
|
33
|
|
|
/** @var SchemaDiffProviderInterface */ |
34
|
|
|
private $originalSchemaManipulator; |
35
|
|
|
|
36
|
113 |
|
public function __construct(LazyLoadingValueHolderFactory $proxyFactory, SchemaDiffProviderInterface $originalSchemaManipulator) |
37
|
|
|
{ |
38
|
113 |
|
$this->proxyFactory = $proxyFactory; |
39
|
113 |
|
$this->originalSchemaManipulator = $originalSchemaManipulator; |
40
|
113 |
|
} |
41
|
|
|
|
42
|
|
|
public static function fromDefaultProxyFacyoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator) |
43
|
|
|
{ |
44
|
|
|
$message = 'Function %s::fromDefaultProxyFacyoryConfiguration() deprecated due to typo.' |
45
|
|
|
. 'Use %s::fromDefaultProxyFactoryConfiguration() instead'; |
46
|
|
|
|
47
|
|
|
trigger_error( |
48
|
|
|
sprintf($message, self::class), |
49
|
|
|
E_USER_DEPRECATED |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
return self::fromDefaultProxyFactoryConfiguration($originalSchemaManipulator); |
53
|
|
|
} |
54
|
|
|
|
55
|
113 |
|
public static function fromDefaultProxyFactoryConfiguration(SchemaDiffProviderInterface $originalSchemaManipulator) |
56
|
|
|
{ |
57
|
113 |
|
$proxyConfig = new Configuration(); |
58
|
113 |
|
$proxyConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); |
59
|
113 |
|
$proxyFactory = new LazyLoadingValueHolderFactory($proxyConfig); |
60
|
|
|
|
61
|
113 |
|
return new LazySchemaDiffProvider($proxyFactory, $originalSchemaManipulator); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return Schema |
66
|
|
|
*/ |
67
|
43 |
|
public function createFromSchema() |
68
|
|
|
{ |
69
|
43 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
70
|
|
|
|
71
|
43 |
|
return $this->proxyFactory->createProxy( |
72
|
43 |
|
Schema::class, |
73
|
|
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator) { |
74
|
13 |
|
$initializer = null; |
75
|
13 |
|
$wrappedObject = $originalSchemaManipulator->createFromSchema(); |
76
|
|
|
|
77
|
13 |
|
return true; |
78
|
|
|
} |
79
|
43 |
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Schema $fromSchema |
84
|
|
|
* @return Schema |
85
|
|
|
*/ |
86
|
41 |
|
public function createToSchema(Schema $fromSchema) |
87
|
|
|
{ |
88
|
41 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
89
|
|
|
|
90
|
41 |
|
if ($fromSchema instanceof LazyLoadingInterface && ! $fromSchema->isProxyInitialized()) { |
91
|
40 |
|
return $this->proxyFactory->createProxy( |
92
|
40 |
|
Schema::class, |
93
|
12 |
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator, $fromSchema) { |
94
|
12 |
|
$initializer = null; |
95
|
12 |
|
$wrappedObject = $originalSchemaManipulator->createToSchema($fromSchema); |
96
|
|
|
|
97
|
12 |
|
return true; |
98
|
|
|
} |
99
|
40 |
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
return $this->originalSchemaManipulator->createToSchema($fromSchema); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param Schema $fromSchema |
107
|
|
|
* @param Schema $toSchema |
108
|
|
|
* |
109
|
|
|
* @return string[] |
110
|
|
|
*/ |
111
|
40 |
|
public function getSqlDiffToMigrate(Schema $fromSchema, Schema $toSchema) |
112
|
|
|
{ |
113
|
|
|
if ( |
114
|
|
|
$toSchema instanceof LazyLoadingInterface |
115
|
40 |
|
&& ! $toSchema->isProxyInitialized() |
116
|
40 |
|
) { |
117
|
32 |
|
return []; |
118
|
|
|
} |
119
|
|
|
|
120
|
13 |
|
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|