Skip to content

Commit

Permalink
improved AbstractConnection::getDb to work without DI too
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Feb 8, 2017
1 parent c3bf1d9 commit 045478b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ abstract class AbstractConnection extends Component implements ConnectionInterfa
protected $_errorChecker;

/**
* @param null $dbname
* @param null $name
* @return ConnectionInterface|AbstractConnection
*/
public static function getDb($dbname = null)
public static function getDb($name = null, $class = ConnectionInterface::class)
{
return $dbname ? Yii::$app->get($dbname) : Yii::$container->get(ConnectionInterface::class);
if ($name) {
return Yii::$app->get($name);
}
if (Yii::$container->hasSingleton($class)) {
return Yii::$container->get($class);
}

return Yii::$app->get(static::$dbname);
}

public function setAuth($auth)
Expand Down

0 comments on commit 045478b

Please sign in to comment.