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\Migrations\Provider\SchemaDiffProviderInterface; |
23
|
|
|
use Doctrine\DBAL\Schema\Schema; |
24
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
25
|
|
|
use ProxyManager\Proxy\LazyLoadingInterface; |
26
|
|
|
|
27
|
|
|
class LazySchemaDiffProvider implements SchemaDiffProviderInterface |
28
|
|
|
{ |
29
|
|
|
/** @var LazyLoadingValueHolderFactory */ |
30
|
|
|
private $proxyFactory; |
31
|
|
|
|
32
|
|
|
/** @var SchemaDiffProviderInterface */ |
33
|
|
|
private $originalSchemaManipulator; |
34
|
|
|
|
35
|
69 |
|
public function __construct(LazyLoadingValueHolderFactory $proxyFactory, SchemaDiffProviderInterface $originalSchemaManipulator) |
36
|
|
|
{ |
37
|
69 |
|
$this->proxyFactory = $proxyFactory; |
38
|
69 |
|
$this->originalSchemaManipulator = $originalSchemaManipulator; |
39
|
69 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return Schema |
43
|
|
|
*/ |
44
|
20 |
|
public function createFromSchema() |
45
|
|
|
{ |
46
|
20 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
47
|
|
|
|
48
|
20 |
|
return $this->proxyFactory->createProxy( |
49
|
20 |
|
Schema::class, |
50
|
|
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator) { |
51
|
12 |
|
$initializer = null; |
52
|
12 |
|
$wrappedObject = $originalSchemaManipulator->createFromSchema(); |
53
|
|
|
|
54
|
12 |
|
return true; |
55
|
12 |
|
} |
56
|
20 |
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Schema $fromSchema |
61
|
|
|
* @return Schema |
62
|
|
|
*/ |
63
|
19 |
|
public function createToSchema(Schema $fromSchema) |
64
|
|
|
{ |
65
|
19 |
|
$originalSchemaManipulator = $this->originalSchemaManipulator; |
66
|
|
|
|
67
|
19 |
|
if ($fromSchema instanceof LazyLoadingInterface && ! $fromSchema->isProxyInitialized()) { |
68
|
18 |
|
return $this->proxyFactory->createProxy( |
69
|
18 |
|
Schema::class, |
70
|
11 |
|
function (& $wrappedObject, $proxy, $method, array $parameters, & $initializer) use ($originalSchemaManipulator, $fromSchema) { |
71
|
11 |
|
$initializer = null; |
72
|
11 |
|
$wrappedObject = $originalSchemaManipulator->createToSchema($fromSchema); |
73
|
|
|
|
74
|
11 |
|
return true; |
75
|
|
|
} |
76
|
18 |
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
return $this->originalSchemaManipulator->createToSchema($fromSchema); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Schema $fromSchema |
84
|
|
|
* @param Schema $toSchema |
85
|
|
|
* |
86
|
|
|
* @return string[] |
87
|
|
|
*/ |
88
|
18 |
|
public function getSqlDiffToMigrate(Schema $fromSchema,Schema $toSchema) |
89
|
|
|
{ |
90
|
|
|
if ( |
91
|
|
|
$toSchema instanceof LazyLoadingInterface |
92
|
18 |
|
&& ! $toSchema->isProxyInitialized() |
93
|
18 |
|
) { |
94
|
11 |
|
return []; |
95
|
|
|
} |
96
|
|
|
|
97
|
12 |
|
return $this->originalSchemaManipulator->getSqlDiffToMigrate($fromSchema, $toSchema); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|