1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: liow.kitloong |
5
|
|
|
* Date: 2020/03/31 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace KitLoong\MigrationsGenerator; |
9
|
|
|
|
10
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
11
|
|
|
use Illuminate\Database\Connection; |
12
|
|
|
use Illuminate\Support\Facades\DB; |
13
|
|
|
use KitLoong\MigrationsGenerator\Generators\Platform; |
14
|
|
|
|
15
|
|
|
class MigrationsGeneratorSetting |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var Connection |
19
|
|
|
*/ |
20
|
|
|
private $connection; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $platform; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var AbstractSchemaManager |
29
|
|
|
*/ |
30
|
|
|
private $schema; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var boolean |
34
|
|
|
*/ |
35
|
|
|
private $ignoreIndexNames; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var boolean |
39
|
|
|
*/ |
40
|
|
|
private $ignoreForeignKeyNames; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return Connection |
44
|
|
|
*/ |
45
|
|
|
public function getConnection(): Connection |
46
|
|
|
{ |
47
|
|
|
return $this->connection; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $connection |
52
|
|
|
*/ |
53
|
|
|
public function setConnection(string $connection): void |
54
|
|
|
{ |
55
|
|
|
$this->connection = DB::connection($connection); |
56
|
|
|
|
57
|
|
|
/** @var \Doctrine\DBAL\Connection $doctConn */ |
58
|
|
|
$doctConn = $this->connection->getDoctrineConnection(); |
59
|
|
|
$this->schema = $doctConn->getSchemaManager(); |
60
|
|
|
$classPath = explode('\\', get_class($doctConn->getDatabasePlatform())); |
61
|
|
|
$platform = end($classPath); |
62
|
|
|
|
63
|
|
|
switch (true) { |
64
|
|
|
case preg_match('/mysql/i', $platform) > 0: |
65
|
|
|
$this->platform = Platform::MYSQL; |
66
|
|
|
break; |
67
|
|
|
case preg_match('/postgresql/i', $platform) > 0: |
68
|
|
|
$this->platform = Platform::POSTGRESQL; |
69
|
|
|
break; |
70
|
|
|
case preg_match('/sqlserver/i', $platform) > 0: |
71
|
|
|
$this->platform = Platform::SQLSERVER; |
72
|
|
|
break; |
73
|
|
|
case preg_match('/sqlite/i', $platform) > 0: |
74
|
|
|
$this->platform = Platform::SQLITE; |
75
|
|
|
break; |
76
|
|
|
default: |
77
|
|
|
$this->platform = Platform::OTHERS; |
78
|
|
|
break; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getPlatform(): string |
86
|
|
|
{ |
87
|
|
|
return $this->platform; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
|
|
public function isIgnoreIndexNames(): bool |
94
|
|
|
{ |
95
|
|
|
return $this->ignoreIndexNames; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param bool $ignoreIndexNames |
100
|
|
|
*/ |
101
|
|
|
public function setIgnoreIndexNames(bool $ignoreIndexNames): void |
102
|
|
|
{ |
103
|
|
|
$this->ignoreIndexNames = $ignoreIndexNames; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function isIgnoreForeignKeyNames(): bool |
110
|
|
|
{ |
111
|
|
|
return $this->ignoreForeignKeyNames; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param bool $ignoreForeignKeyNames |
116
|
|
|
*/ |
117
|
|
|
public function setIgnoreForeignKeyNames(bool $ignoreForeignKeyNames): void |
118
|
|
|
{ |
119
|
|
|
$this->ignoreForeignKeyNames = $ignoreForeignKeyNames; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return AbstractSchemaManager |
124
|
|
|
*/ |
125
|
|
|
public function getSchema(): AbstractSchemaManager |
126
|
|
|
{ |
127
|
|
|
return $this->schema; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|