Skip to content

Commit ce2d3dc

Browse files
committed
Merge branch 'pr6663' into 8.x
2 parents 6718ae6 + d1a32f9 commit ce2d3dc

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class Connection implements ConnectionInterface
4949
*/
5050
protected $database;
5151

52+
/**
53+
* The type of the connection.
54+
*
55+
* @var string|null
56+
*/
57+
protected $type;
58+
5259
/**
5360
* The table prefix for the connection.
5461
*
@@ -1045,6 +1052,16 @@ public function getName()
10451052
return $this->getConfig('name');
10461053
}
10471054

1055+
/**
1056+
* Get the database connection full name.
1057+
*
1058+
* @return string|null
1059+
*/
1060+
public function getNameWithReadWriteType()
1061+
{
1062+
return $this->getName().($this->readWriteType ? '::'.$this->readWriteType : '');
1063+
}
1064+
10481065
/**
10491066
* Get an option from the configuration options.
10501067
*
@@ -1274,6 +1291,19 @@ public function setDatabaseName($database)
12741291
return $this;
12751292
}
12761293

1294+
/**
1295+
* Set the read / write type of the connection.
1296+
*
1297+
* @param string|null $readWriteType
1298+
* @return $this
1299+
*/
1300+
public function setReadWriteType($readWriteType)
1301+
{
1302+
$this->readWriteType = $readWriteType;
1303+
1304+
return $this;
1305+
}
1306+
12771307
/**
12781308
* Get the table prefix for the connection.
12791309
*

src/Illuminate/Database/DatabaseManager.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($app, ConnectionFactory $factory)
6262
$this->factory = $factory;
6363

6464
$this->reconnector = function ($connection) {
65-
$this->reconnect($connection->getName());
65+
$this->reconnect($connection->getNameWithReadWriteType());
6666
};
6767
}
6868

@@ -165,7 +165,7 @@ protected function configuration($name)
165165
*/
166166
protected function configure(Connection $connection, $type)
167167
{
168-
$connection = $this->setPdoForType($connection, $type);
168+
$connection = $this->setPdoForType($connection, $type)->setReadWriteType($type);
169169

170170
// First we'll set the fetch mode and a few other dependencies of the database
171171
// connection. This method basically just configures and prepares it to get
@@ -275,11 +275,15 @@ public function usingConnection($name, callable $callback)
275275
*/
276276
protected function refreshPdoConnections($name)
277277
{
278-
$fresh = $this->makeConnection($name);
278+
[$database, $type] = $this->parseConnectionName($name);
279+
280+
$fresh = $this->configure(
281+
$this->makeConnection($database), $type
282+
);
279283

280284
return $this->connections[$name]
281-
->setPdo($fresh->getRawPdo())
282-
->setReadPdo($fresh->getRawReadPdo());
285+
->setPdo($fresh->getRawPdo())
286+
->setReadPdo($fresh->getRawReadPdo());
283287
}
284288

285289
/**

0 commit comments

Comments
 (0)