1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: liow.kitloong |
5
|
|
|
* Date: 2020/03/31 |
6
|
|
|
* Time: 22:55 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace KitLoong\MigrationsGenerator; |
10
|
|
|
|
11
|
|
|
use Illuminate\Support\Facades\DB; |
12
|
|
|
use KitLoong\MigrationsGenerator\Generators\Platform; |
13
|
|
|
|
14
|
|
|
class MigrationGeneratorSetting |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $connection; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
23
|
|
|
*/ |
24
|
|
|
private $databasePlatform; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $platform; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getConnection(): string |
35
|
|
|
{ |
36
|
|
|
return $this->connection; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $connection |
41
|
|
|
*/ |
42
|
|
|
public function setConnection(string $connection): void |
43
|
|
|
{ |
44
|
|
|
$this->connection = $connection; |
45
|
|
|
|
46
|
|
|
/** @var \Doctrine\DBAL\Connection $doctConn */ |
47
|
|
|
$doctConn = DB::connection($this->connection)->getDoctrineConnection(); |
48
|
|
|
$this->databasePlatform = $doctConn->getDatabasePlatform(); |
49
|
|
|
$classPath = explode('\\', get_class($this->databasePlatform)); |
50
|
|
|
$platform = end($classPath); |
51
|
|
|
|
52
|
|
|
switch (true) { |
|
|
|
|
53
|
|
|
case preg_match('/mysql/i', $platform): |
54
|
|
|
$this->platform = Platform::MYSQL; |
55
|
|
|
break; |
56
|
|
|
case preg_match('/postgresql/i', $platform): |
57
|
|
|
$this->platform = Platform::POSTGRESQL; |
58
|
|
|
break; |
59
|
|
|
case preg_match('/sqlserver/i', $platform): |
60
|
|
|
$this->platform = Platform::SQLSERVER; |
61
|
|
|
break; |
62
|
|
|
case preg_match('/sqlite/i', $platform): |
63
|
|
|
$this->platform = Platform::SQLITE; |
64
|
|
|
break; |
65
|
|
|
default: |
66
|
|
|
$this->platform = Platform::OTHERS; |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \Doctrine\DBAL\Platforms\AbstractPlatform |
73
|
|
|
*/ |
74
|
|
|
public function getDatabasePlatform(): \Doctrine\DBAL\Platforms\AbstractPlatform |
75
|
|
|
{ |
76
|
|
|
return $this->databasePlatform; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getPlatform(): string |
83
|
|
|
{ |
84
|
|
|
return $this->platform; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|