MediaWiki REL1_39
DoctrineSchemaBuilderFactory.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use Doctrine\DBAL\Platforms\AbstractPlatform;
6use Doctrine\DBAL\Platforms\SqlitePlatform;
7use Doctrine\DBAL\Types\Type;
8use InvalidArgumentException;
9
15
20 public function getSchemaBuilder( string $platform ) {
21 return new DoctrineSchemaBuilder( $this->getPlatform( $platform ) );
22 }
23
28 public function getSchemaChangeBuilder( $platform ) {
29 return new DoctrineSchemaChangeBuilder( $this->getPlatform( $platform ) );
30 }
31
36 private function getPlatform( string $platform ) {
37 switch ( $platform ) {
38 case 'mysql':
39 $platformObject = new MWMySQLPlatform;
40 break;
41 case 'postgres':
42 $platformObject = new MWPostgreSqlPlatform;
43 break;
44 case 'sqlite':
45 $platformObject = new SqlitePlatform;
46 break;
47 default:
48 throw new InvalidArgumentException( 'Unknown platform: ' . $platform );
49 }
50
51 $customTypes = [
52 'Enum' => [ EnumType::class, EnumType::ENUM ],
53 'Tinyint' => [ TinyIntType::class, TinyIntType::TINYINT ],
54 'Timestamp' => [ TimestampType::class, TimestampType::TIMESTAMP ],
55 ];
56
57 foreach ( $customTypes as $type => [ $class, $name ] ) {
58 if ( !Type::hasType( $name ) ) {
59 Type::addType( $name, $class );
60 }
61 $platformObject->registerDoctrineTypeMapping( $type, $name );
62 }
63
64 return $platformObject;
65 }
66}