Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DoctrineSchemaBuilderFactory | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| getSchemaBuilder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSchemaChangeBuilder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPlatform | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Wikimedia\Rdbms; |
| 4 | |
| 5 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 | use Doctrine\DBAL\Platforms\SqlitePlatform; |
| 7 | use Doctrine\DBAL\Types\Type; |
| 8 | use InvalidArgumentException; |
| 9 | |
| 10 | /** |
| 11 | * @experimental |
| 12 | * @unstable |
| 13 | */ |
| 14 | class DoctrineSchemaBuilderFactory { |
| 15 | |
| 16 | /** |
| 17 | * @param string $platform one of strings 'mysql', 'postgres' or 'sqlite' |
| 18 | * @return DoctrineSchemaBuilder |
| 19 | */ |
| 20 | public function getSchemaBuilder( string $platform ) { |
| 21 | return new DoctrineSchemaBuilder( $this->getPlatform( $platform ) ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @param string $platform one of strings 'mysql', 'postgres' or 'sqlite' |
| 26 | * @return DoctrineSchemaChangeBuilder |
| 27 | */ |
| 28 | public function getSchemaChangeBuilder( $platform ) { |
| 29 | return new DoctrineSchemaChangeBuilder( $this->getPlatform( $platform ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @param string $platform |
| 34 | * @return AbstractPlatform |
| 35 | */ |
| 36 | private function getPlatform( string $platform ) { |
| 37 | $platformObject = match ( $platform ) { |
| 38 | 'mysql' => new MWMySQLPlatform(), |
| 39 | 'postgres' => new MWPostgreSqlPlatform(), |
| 40 | 'sqlite' => new SqlitePlatform(), |
| 41 | default => throw new InvalidArgumentException( "Unknown platform: $platform" ) |
| 42 | }; |
| 43 | |
| 44 | $customTypes = [ |
| 45 | 'Enum' => [ EnumType::class, EnumType::ENUM ], |
| 46 | 'Tinyint' => [ TinyIntType::class, TinyIntType::TINYINT ], |
| 47 | 'Timestamp' => [ TimestampType::class, TimestampType::TIMESTAMP ], |
| 48 | ]; |
| 49 | |
| 50 | foreach ( $customTypes as $type => [ $class, $name ] ) { |
| 51 | if ( !Type::hasType( $name ) ) { |
| 52 | Type::addType( $name, $class ); |
| 53 | } |
| 54 | $platformObject->registerDoctrineTypeMapping( $type, $name ); |
| 55 | } |
| 56 | |
| 57 | return $platformObject; |
| 58 | } |
| 59 | } |