for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SWL;
use DatabaseBase;
use RuntimeException;
/**
* @license GNU GPL v2+
* @since 1.2
*
* @author Jeroen De Dauw < [email protected] >
*/
class LazyDBConnectionProvider {
* @var DatabaseBase|null
protected $connection = null;
* @var int|null
protected $connectionId = null;
* @var string|array
protected $groups;
* @var string|boolean $wiki
protected $wiki;
* @param int $connectionId
* @param string|array $groups
* @param string|boolean $wiki
public function __construct( $connectionId, $groups = array(), $wiki = false ) {
$this->connectionId = $connectionId;
$this->groups = $groups;
$this->wiki = $wiki;
}
* @see DBConnectionProvider::getConnection
* @return DatabaseBase
* @throws RuntimeException
public function getConnection() {
if ( $this->connection === null ) {
$this->connection = wfGetLB( $this->wiki )->getConnection( $this->connectionId, $this->groups, $this->wiki );
if ( $this->isConnection( $this->connection ) ) {
return $this->connection;
throw new RuntimeException( 'Expected a DatabaseBase instance' );
* @see DBConnectionProvider::releaseConnection
public function releaseConnection() {
if ( $this->wiki !== false && $this->connection !== null ) {
wfGetLB( $this->wiki )->reuseConnection( $this->connection );
protected function isConnection( $connection ) {
return $connection instanceof DatabaseBase;
DatabaseBase