Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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