Skip to content

Commit 334e298

Browse files
authored
Merge pull request #4092 from morozov/remove-connection-is-connected
Remove Connection::$isConnected
2 parents 1738936 + 2cedd22 commit 334e298

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

lib/Doctrine/DBAL/Connection.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ class Connection implements DriverConnection
9898
/** @var ExpressionBuilder */
9999
protected $_expr;
100100

101-
/**
102-
* Whether or not a connection has been established.
103-
*
104-
* @var bool
105-
*/
106-
private $isConnected = false;
107-
108101
/**
109102
* The current auto-commit mode of this connection.
110103
*
@@ -192,8 +185,7 @@ public function __construct(
192185
$this->params = $params;
193186

194187
if (isset($params['pdo'])) {
195-
$this->_conn = $params['pdo'];
196-
$this->isConnected = true;
188+
$this->_conn = $params['pdo'];
197189
unset($this->params['pdo']);
198190
}
199191

@@ -356,16 +348,15 @@ public function getExpressionBuilder()
356348
*/
357349
public function connect()
358350
{
359-
if ($this->isConnected) {
351+
if ($this->_conn !== null) {
360352
return false;
361353
}
362354

363355
$driverOptions = $this->params['driverOptions'] ?? [];
364356
$user = $this->params['user'] ?? null;
365357
$password = $this->params['password'] ?? null;
366358

367-
$this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions);
368-
$this->isConnected = true;
359+
$this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions);
369360

370361
$this->transactionNestingLevel = 0;
371362

@@ -524,7 +515,7 @@ public function setAutoCommit($autoCommit)
524515
$this->autoCommit = $autoCommit;
525516

526517
// Commit all currently active transactions if any when switching auto-commit mode.
527-
if ($this->isConnected !== true || $this->transactionNestingLevel === 0) {
518+
if ($this->_conn === null || $this->transactionNestingLevel === 0) {
528519
return;
529520
}
530521

@@ -689,7 +680,7 @@ public function fetchOne(string $query, array $params = [], array $types = [])
689680
*/
690681
public function isConnected()
691682
{
692-
return $this->isConnected;
683+
return $this->_conn !== null;
693684
}
694685

695686
/**
@@ -771,8 +762,6 @@ public function delete($tableExpression, array $identifier, array $types = [])
771762
public function close()
772763
{
773764
$this->_conn = null;
774-
775-
$this->isConnected = false;
776765
}
777766

778767
/**

0 commit comments

Comments
 (0)