|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Schema\Visitor; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
6
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
|
7
|
|
|
use Doctrine\DBAL\Schema\Sequence; |
|
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
|
9
|
|
|
use Doctrine\DBAL\Schema\View; |
|
10
|
|
|
use function array_merge; |
|
11
|
|
|
|
|
12
|
|
|
class CreateSchemaSqlCollector extends AbstractVisitor |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var string[] */ |
|
15
|
|
|
private $createNamespaceQueries = []; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string[] */ |
|
18
|
|
|
private $createTableQueries = []; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string[] */ |
|
21
|
|
|
private $createSequenceQueries = []; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string[] */ |
|
24
|
|
|
private $createFkConstraintQueries = []; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string[] */ |
|
27
|
|
|
private $createViewQueries = []; |
|
28
|
|
|
|
|
29
|
|
|
/** @var AbstractPlatform */ |
|
30
|
|
|
private $platform = null; |
|
31
|
|
|
|
|
32
|
333 |
|
public function __construct(AbstractPlatform $platform) |
|
33
|
|
|
{ |
|
34
|
333 |
|
$this->platform = $platform; |
|
35
|
333 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
76 |
|
public function acceptNamespace($namespaceName) |
|
41
|
|
|
{ |
|
42
|
76 |
|
if (! $this->platform->supportsSchemas()) { |
|
43
|
57 |
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
38 |
|
$this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName); |
|
47
|
38 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
257 |
|
public function acceptTable(Table $table) |
|
53
|
|
|
{ |
|
54
|
257 |
|
$this->createTableQueries = array_merge($this->createTableQueries, (array) $this->platform->getCreateTableSQL($table)); |
|
55
|
257 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
57 |
|
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) |
|
61
|
|
|
{ |
|
62
|
57 |
|
if (! $this->platform->supportsForeignKeyConstraints()) { |
|
63
|
19 |
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
57 |
|
$this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable); |
|
67
|
57 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
57 |
|
public function acceptSequence(Sequence $sequence) |
|
73
|
|
|
{ |
|
74
|
57 |
|
$this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence); |
|
75
|
57 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
38 |
|
public function acceptView(View $view) |
|
81
|
|
|
{ |
|
82
|
38 |
|
$this->createViewQueries[] = $this->platform->getCreateViewSQL($view->getName(), $view->getSql()); |
|
83
|
38 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
19 |
|
public function resetQueries() |
|
89
|
|
|
{ |
|
90
|
19 |
|
$this->createNamespaceQueries = []; |
|
91
|
19 |
|
$this->createTableQueries = []; |
|
92
|
19 |
|
$this->createSequenceQueries = []; |
|
93
|
19 |
|
$this->createFkConstraintQueries = []; |
|
94
|
19 |
|
$this->createViewQueries = []; |
|
95
|
19 |
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Gets all queries collected so far. |
|
99
|
|
|
* |
|
100
|
|
|
* @return string[] |
|
101
|
|
|
*/ |
|
102
|
333 |
|
public function getQueries() |
|
103
|
|
|
{ |
|
104
|
333 |
|
return array_merge( |
|
105
|
333 |
|
$this->createNamespaceQueries, |
|
106
|
333 |
|
$this->createTableQueries, |
|
107
|
333 |
|
$this->createSequenceQueries, |
|
108
|
333 |
|
$this->createFkConstraintQueries, |
|
109
|
333 |
|
$this->createViewQueries |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|