blob: 5f6a77a7a7e1a48125292c7cf948bfe72bafd841 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\SQL\Builder;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
final class CreateSchemaObjectsSQLBuilder
{
public function __construct(private readonly AbstractPlatform $platform)
{
}
/** @return list<string> */
public function buildSQL(Schema $schema): array
{
return array_merge(
$this->buildNamespaceStatements($schema->getNamespaces()),
$this->buildSequenceStatements($schema->getSequences()),
$this->buildTableStatements($schema->getTables()),
);
}
/**
* @param list<string> $namespaces
*
* @return list<string>
*/
private function buildNamespaceStatements(array $namespaces): array
{
$statements = [];
if ($this->platform->supportsSchemas()) {
foreach ($namespaces as $namespace) {
$statements[] = $this->platform->getCreateSchemaSQL($namespace);
}
}
return $statements;
}
/**
* @param list<Table> $tables
*
* @return list<string>
*/
private function buildTableStatements(array $tables): array
{
return $this->platform->getCreateTablesSQL($tables);
}
/**
* @param list<Sequence> $sequences
*
* @return list<string>
*/
private function buildSequenceStatements(array $sequences): array
{
$statements = [];
foreach ($sequences as $sequence) {
$statements[] = $this->platform->getCreateSequenceSQL($sequence);
}
return $statements;
}
}
|