Skip to content

Commit

Permalink
Connection: $connected replaced with $driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 2, 2018
1 parent 87c9f61 commit 2e2e4ad
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/Dibi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class Connection implements IConnection
/** @var Translator|null */
private $translator;

/** @var bool Is connected? */
private $connected = false;

/** @var HashMap Substitutes for identifiers */
private $substitutes;

Expand Down Expand Up @@ -126,7 +123,6 @@ final public function connect(): void
$event = $this->onEvent ? new Event($this, Event::CONNECT) : null;
try {
$this->driver = new $class($this->config);
$this->connected = true;
if ($event) {
$this->onEvent($event->done());
}
Expand All @@ -145,8 +141,8 @@ final public function connect(): void
*/
final public function disconnect(): void
{
if ($this->connected) {
$this->connected = false;
if ($this->driver) {
$this->driver = null;
}
}

Expand All @@ -156,7 +152,7 @@ final public function disconnect(): void
*/
final public function isConnected(): bool
{
return $this->connected;
return (bool) $this->driver;
}


Expand All @@ -178,7 +174,7 @@ final public function getConfig(string $key = null, $default = null)
*/
final public function getDriver(): Driver
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
return $this->driver;
Expand Down Expand Up @@ -245,7 +241,7 @@ final public function dataSource(...$args): DataSource
*/
protected function translateArgs(array $args): string
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
if (!$this->translator) {
Expand All @@ -263,7 +259,7 @@ protected function translateArgs(array $args): string
*/
final public function nativeQuery(string $sql)
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}

Expand Down Expand Up @@ -298,7 +294,7 @@ final public function nativeQuery(string $sql)
*/
public function getAffectedRows(): int
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
$rows = $this->driver->getAffectedRows();
Expand All @@ -325,7 +321,7 @@ public function affectedRows(): int
*/
public function getInsertId(string $sequence = null): int
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
$id = $this->driver->getInsertId($sequence);
Expand All @@ -351,7 +347,7 @@ public function insertId(string $sequence = null): int
*/
public function begin(string $savepoint = null): void
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
$event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : null;
Expand All @@ -375,7 +371,7 @@ public function begin(string $savepoint = null): void
*/
public function commit(string $savepoint = null): void
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
$event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : null;
Expand All @@ -399,7 +395,7 @@ public function commit(string $savepoint = null): void
*/
public function rollback(string $savepoint = null): void
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
$event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : null;
Expand Down Expand Up @@ -569,7 +565,7 @@ public function loadFile(string $file, callable $onProgress = null): int
*/
public function getDatabaseInfo(): Reflection\Database
{
if (!$this->connected) {
if (!$this->driver) {
$this->connect();
}
return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? null);
Expand Down

0 comments on commit 2e2e4ad

Please sign in to comment.