MediaWiki  master
DoctrineSchemaBuilderFactory.php
Go to the documentation of this file.
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 
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 }
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory\getSchemaBuilder
getSchemaBuilder(string $platform)
Definition: DoctrineSchemaBuilderFactory.php:20
Wikimedia\Rdbms\TinyIntType\TINYINT
const TINYINT
Definition: TinyIntType.php:13
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory\getPlatform
getPlatform(string $platform)
Definition: DoctrineSchemaBuilderFactory.php:36
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory\getSchemaChangeBuilder
getSchemaChangeBuilder( $platform)
Definition: DoctrineSchemaBuilderFactory.php:28
Wikimedia\Rdbms\MWPostgreSqlPlatform
Definition: MWPostgreSqlPlatform.php:10
Wikimedia\Rdbms\DoctrineSchemaBuilder
@experimental
Definition: DoctrineSchemaBuilder.php:12
Wikimedia\Rdbms\TimestampType\TIMESTAMP
const TIMESTAMP
Definition: TimestampType.php:13
Wikimedia\Rdbms\MWMySQLPlatform
Definition: MWMySQLPlatform.php:8
Wikimedia\Rdbms\DoctrineSchemaBuilderFactory
@experimental
Definition: DoctrineSchemaBuilderFactory.php:14
Wikimedia\Rdbms\DoctrineSchemaChangeBuilder
@experimental
Definition: DoctrineSchemaChangeBuilder.php:13
Wikimedia\Rdbms\EnumType\ENUM
const ENUM
Definition: EnumType.php:18
$type
$type
Definition: testCompression.php:52