@@ -34,24 +34,34 @@ public function withDatabaseConnection(
34
34
string $ username ,
35
35
string $ password ,
36
36
string $ dbname ,
37
- string $ tablePrefix = ''
37
+ string $ connectionName = 'default '
38
38
): self {
39
- return $ this -> withSetting ( ' db/table_prefix ' , $ tablePrefix )
40
- ->withSetting (' db/connection/default/ host ' , $ host )
41
- ->withSetting (' db/connection/default/ username ' , $ username )
42
- ->withSetting (' db/connection/default/ password ' , $ password )
43
- ->withSetting (' db/connection/default/ dbname ' , $ dbname )
44
- ->withSetting (' db/connection/default/ active ' , 1 )
45
- ->withSetting (' db/connection/default/ engine ' , 'innodb ' )
46
- ->withSetting (' db/connection/default/ initStatements ' , ['SET NAMES utf8 ' ])
47
- ->withSetting (' db/connection/default/ driver_options ' , [
48
- PDO ::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
49
- ]);
39
+ return $ this
40
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' host ') , $ host )
41
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' username ') , $ username )
42
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' password ') , $ password )
43
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' dbname ') , $ dbname )
44
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' active ') , 1 )
45
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' engine ') , 'innodb ' )
46
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' initStatements ') , ['SET NAMES utf8 ' ])
47
+ ->withSetting ($ this -> databaseSettingPath ( $ connectionName , ' driver_options ') , [
48
+ PDO ::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
49
+ ]);
50
50
}
51
51
52
52
public function withSetting (string $ path , mixed $ value ): self
53
53
{
54
54
$ data = $ this ->data ->withValue ('file ' , $ path , $ value );
55
55
return new self ($ data );
56
56
}
57
+
58
+ public function withTablePrefix (string $ prefix ): self
59
+ {
60
+ return $ this ->withSetting ('db/table_prefix ' , $ prefix );
61
+ }
62
+
63
+ private function databaseSettingPath (string $ connectionName , string $ path )
64
+ {
65
+ return sprintf ('db/connection/%s/%s ' , $ connectionName , $ path );
66
+ }
57
67
}
0 commit comments