| 148 |
lars |
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\Deprecations\Deprecation;
|
|
|
10 |
|
|
|
11 |
use function array_merge;
|
|
|
12 |
|
|
|
13 |
/** @deprecated Use {@link CreateSchemaObjectsSQLBuilder} instead. */
|
|
|
14 |
class CreateSchemaSqlCollector extends AbstractVisitor
|
|
|
15 |
{
|
|
|
16 |
/** @var string[] */
|
|
|
17 |
private array $createNamespaceQueries = [];
|
|
|
18 |
|
|
|
19 |
/** @var string[] */
|
|
|
20 |
private array $createTableQueries = [];
|
|
|
21 |
|
|
|
22 |
/** @var string[] */
|
|
|
23 |
private array $createSequenceQueries = [];
|
|
|
24 |
|
|
|
25 |
/** @var string[] */
|
|
|
26 |
private array $createFkConstraintQueries = [];
|
|
|
27 |
|
|
|
28 |
private AbstractPlatform $platform;
|
|
|
29 |
|
|
|
30 |
public function __construct(AbstractPlatform $platform)
|
|
|
31 |
{
|
|
|
32 |
Deprecation::trigger(
|
|
|
33 |
'doctrine/dbal',
|
|
|
34 |
'https://github.com/doctrine/dbal/pull/5416',
|
|
|
35 |
'CreateSchemaSqlCollector is deprecated. Use CreateSchemaObjectsSQLBuilder instead.',
|
|
|
36 |
);
|
|
|
37 |
|
|
|
38 |
$this->platform = $platform;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* {@inheritdoc}
|
|
|
43 |
*/
|
|
|
44 |
public function acceptNamespace($namespaceName)
|
|
|
45 |
{
|
|
|
46 |
if (! $this->platform->supportsSchemas()) {
|
|
|
47 |
return;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* {@inheritdoc}
|
|
|
55 |
*/
|
|
|
56 |
public function acceptTable(Table $table)
|
|
|
57 |
{
|
|
|
58 |
$this->createTableQueries = array_merge($this->createTableQueries, $this->platform->getCreateTableSQL($table));
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* {@inheritdoc}
|
|
|
63 |
*/
|
|
|
64 |
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
|
|
|
65 |
{
|
|
|
66 |
if (! $this->platform->supportsForeignKeyConstraints()) {
|
|
|
67 |
return;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
$this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* {@inheritdoc}
|
|
|
75 |
*/
|
|
|
76 |
public function acceptSequence(Sequence $sequence)
|
|
|
77 |
{
|
|
|
78 |
$this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/** @return void */
|
|
|
82 |
public function resetQueries()
|
|
|
83 |
{
|
|
|
84 |
$this->createNamespaceQueries = [];
|
|
|
85 |
$this->createTableQueries = [];
|
|
|
86 |
$this->createSequenceQueries = [];
|
|
|
87 |
$this->createFkConstraintQueries = [];
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Gets all queries collected so far.
|
|
|
92 |
*
|
|
|
93 |
* @return string[]
|
|
|
94 |
*/
|
|
|
95 |
public function getQueries()
|
|
|
96 |
{
|
|
|
97 |
return array_merge(
|
|
|
98 |
$this->createNamespaceQueries,
|
|
|
99 |
$this->createSequenceQueries,
|
|
|
100 |
$this->createTableQueries,
|
|
|
101 |
$this->createFkConstraintQueries,
|
|
|
102 |
);
|
|
|
103 |
}
|
|
|
104 |
}
|