mailpoet
/
vendor-prefixed
/
doctrine
/
dbal
/
src
/
SQL
/
Builder
/
CreateSchemaObjectsSQLBuilder.php
CreateSchemaObjectsSQLBuilder.php
2 years ago
DefaultSelectSQLBuilder.php
2 years ago
DropSchemaObjectsSQLBuilder.php
2 years ago
SelectSQLBuilder.php
2 years ago
index.php
2 years ago
CreateSchemaObjectsSQLBuilder.php
44 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\SQL\Builder; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Exception; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Schema\Schema; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Schema\Sequence; |
| 8 | use MailPoetVendor\Doctrine\DBAL\Schema\Table; |
| 9 | use function array_merge; |
| 10 | final class CreateSchemaObjectsSQLBuilder |
| 11 | { |
| 12 | private AbstractPlatform $platform; |
| 13 | public function __construct(AbstractPlatform $platform) |
| 14 | { |
| 15 | $this->platform = $platform; |
| 16 | } |
| 17 | public function buildSQL(Schema $schema) : array |
| 18 | { |
| 19 | return array_merge($this->buildNamespaceStatements($schema->getNamespaces()), $this->buildSequenceStatements($schema->getSequences()), $this->buildTableStatements($schema->getTables())); |
| 20 | } |
| 21 | private function buildNamespaceStatements(array $namespaces) : array |
| 22 | { |
| 23 | $statements = []; |
| 24 | if ($this->platform->supportsSchemas()) { |
| 25 | foreach ($namespaces as $namespace) { |
| 26 | $statements[] = $this->platform->getCreateSchemaSQL($namespace); |
| 27 | } |
| 28 | } |
| 29 | return $statements; |
| 30 | } |
| 31 | private function buildTableStatements(array $tables) : array |
| 32 | { |
| 33 | return $this->platform->getCreateTablesSQL($tables); |
| 34 | } |
| 35 | private function buildSequenceStatements(array $sequences) : array |
| 36 | { |
| 37 | $statements = []; |
| 38 | foreach ($sequences as $sequence) { |
| 39 | $statements[] = $this->platform->getCreateSequenceSQL($sequence); |
| 40 | } |
| 41 | return $statements; |
| 42 | } |
| 43 | } |
| 44 |