MediaWiki master
DoctrineSchemaBuilderFactory.php
Go to the documentation of this file.
1<?php
2
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 $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}