MediaWiki  1.30.0
LoadBalancerSingle.php
Go to the documentation of this file.
1 <?php
24 namespace Wikimedia\Rdbms;
25 
26 use InvalidArgumentException;
27 
33  private $db;
34 
39  public function __construct( array $params ) {
40  if ( !isset( $params['connection'] ) ) {
41  throw new InvalidArgumentException( "Missing 'connection' argument." );
42  }
43 
44  $this->db = $params['connection'];
45 
46  parent::__construct( [
47  'servers' => [
48  [
49  'type' => $this->db->getType(),
50  'host' => $this->db->getServer(),
51  'dbname' => $this->db->getDBname(),
52  'load' => 1,
53  ]
54  ],
55  'trxProfiler' => isset( $params['trxProfiler'] ) ? $params['trxProfiler'] : null,
56  'srvCache' => isset( $params['srvCache'] ) ? $params['srvCache'] : null,
57  'wanCache' => isset( $params['wanCache'] ) ? $params['wanCache'] : null
58  ] );
59 
60  if ( isset( $params['readOnlyReason'] ) ) {
61  $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
62  }
63  }
64 
71  public static function newFromConnection( IDatabase $db, array $params = [] ) {
72  return new static( [ 'connection' => $db ] + $params );
73  }
74 
75  protected function reallyOpenConnection( array $server, $dbNameOverride = false ) {
76  return $this->db;
77  }
78 }
79 
80 class_alias( 'Wikimedia\Rdbms\LoadBalancerSingle', 'LoadBalancerSingle' );
Wikimedia\Rdbms\LoadBalancerSingle
Trivial LoadBalancer that always returns an injected connection handle.
Definition: LoadBalancerSingle.php:31
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
$params
$params
Definition: styleTest.css.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
Wikimedia\Rdbms\LoadBalancer
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition: LoadBalancer.php:41
Wikimedia\Rdbms\LoadBalancerSingle\newFromConnection
static newFromConnection(IDatabase $db, array $params=[])
Definition: LoadBalancerSingle.php:71
Wikimedia\Rdbms\LoadBalancerSingle\$db
IDatabase $db
Definition: LoadBalancerSingle.php:33
Wikimedia\Rdbms\LoadBalancerSingle\__construct
__construct(array $params)
Definition: LoadBalancerSingle.php:39
Wikimedia\Rdbms\LoadBalancerSingle\reallyOpenConnection
reallyOpenConnection(array $server, $dbNameOverride=false)
Really opens a connection.
Definition: LoadBalancerSingle.php:75
array
the array() calling protocol came about after MediaWiki 1.4rc1.