[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/db/ -> LBFactorySingle.php (source)

   1  <?php
   2  /**
   3   * Simple generator of database connections that always returns the same object.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Database
  22   */
  23  
  24  /**
  25   * An LBFactory class that always returns a single database object.
  26   */
  27  class LBFactorySingle extends LBFactory {
  28      /** @var LoadBalancerSingle */
  29      protected $lb;
  30  
  31      /**
  32       * @param array $conf An associative array with one member:
  33       *  - connection: The DatabaseBase connection object
  34       */
  35  	function __construct( $conf ) {
  36          $this->lb = new LoadBalancerSingle( $conf );
  37      }
  38  
  39      /**
  40       * @param bool|string $wiki
  41       * @return LoadBalancerSingle
  42       */
  43  	function newMainLB( $wiki = false ) {
  44          return $this->lb;
  45      }
  46  
  47      /**
  48       * @param bool|string $wiki
  49       * @return LoadBalancerSingle
  50       */
  51  	function getMainLB( $wiki = false ) {
  52          return $this->lb;
  53      }
  54  
  55      /**
  56       * @param string $cluster External storage cluster, or false for core
  57       * @param bool|string $wiki Wiki ID, or false for the current wiki
  58       * @return LoadBalancerSingle
  59       */
  60  	function newExternalLB( $cluster, $wiki = false ) {
  61          return $this->lb;
  62      }
  63  
  64      /**
  65       * @param string $cluster External storage cluster, or false for core
  66       * @param bool|string $wiki Wiki ID, or false for the current wiki
  67       * @return LoadBalancerSingle
  68       */
  69      function &getExternalLB( $cluster, $wiki = false ) {
  70          return $this->lb;
  71      }
  72  
  73      /**
  74       * @param string|callable $callback
  75       * @param array $params
  76       */
  77  	function forEachLB( $callback, $params = array() ) {
  78          call_user_func_array( $callback, array_merge( array( $this->lb ), $params ) );
  79      }
  80  }
  81  
  82  /**
  83   * Helper class for LBFactorySingle.
  84   */
  85  class LoadBalancerSingle extends LoadBalancer {
  86      /** @var DatabaseBase */
  87      protected $db;
  88  
  89      /**
  90       * @param array $params
  91       */
  92  	function __construct( $params ) {
  93          $this->db = $params['connection'];
  94          parent::__construct( array( 'servers' => array( array(
  95              'type' => $this->db->getType(),
  96              'host' => $this->db->getServer(),
  97              'dbname' => $this->db->getDBname(),
  98              'load' => 1,
  99          ) ) ) );
 100      }
 101  
 102      /**
 103       *
 104       * @param string $server
 105       * @param bool $dbNameOverride
 106       *
 107       * @return DatabaseBase
 108       */
 109  	function reallyOpenConnection( $server, $dbNameOverride = false ) {
 110          return $this->db;
 111      }
 112  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1