function __construct() { $this->cliMode = true; $this->connLogger = new \Psr\Log\NullLogger(); $this->queryLogger = new \Psr\Log\NullLogger(); $this->errorLogger = function (Exception $e) { wfWarn(get_class($e) . ": {$e->getMessage()}"); }; $this->currentDomain = DatabaseDomain::newUnspecified(); }
public function __construct($testName, array $opts = []) { $this->testName = $testName; $this->profiler = new ProfilerStub([]); $this->trxProfiler = new TransactionProfiler(); $this->cliMode = isset($opts['cliMode']) ? $opts['cliMode'] : true; $this->connLogger = new \Psr\Log\NullLogger(); $this->queryLogger = new \Psr\Log\NullLogger(); $this->errorLogger = function (Exception $e) { wfWarn(get_class($e) . ": {$e->getMessage()}"); }; $this->currentDomain = DatabaseDomain::newUnspecified(); }
public function __construct(array $conf) { $this->localDomain = isset($conf['localDomain']) ? DatabaseDomain::newFromId($conf['localDomain']) : DatabaseDomain::newUnspecified(); if (isset($conf['readOnlyReason']) && is_string($conf['readOnlyReason'])) { $this->readOnlyReason = $conf['readOnlyReason']; } $this->srvCache = isset($conf['srvCache']) ? $conf['srvCache'] : new EmptyBagOStuff(); $this->memCache = isset($conf['memCache']) ? $conf['memCache'] : new EmptyBagOStuff(); $this->wanCache = isset($conf['wanCache']) ? $conf['wanCache'] : WANObjectCache::newEmpty(); foreach (self::$loggerFields as $key) { $this->{$key} = isset($conf[$key]) ? $conf[$key] : new \Psr\Log\NullLogger(); } $this->errorLogger = isset($conf['errorLogger']) ? $conf['errorLogger'] : function (Exception $e) { trigger_error(E_USER_WARNING, get_class($e) . ': ' . $e->getMessage()); }; $this->profiler = isset($params['profiler']) ? $params['profiler'] : null; $this->trxProfiler = isset($conf['trxProfiler']) ? $conf['trxProfiler'] : new TransactionProfiler(); $this->requestInfo = ['IPAddress' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'UserAgent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'ChronologyProtection' => 'true']; $this->cliMode = isset($params['cliMode']) ? $params['cliMode'] : PHP_SAPI === 'cli'; $this->hostname = isset($conf['hostname']) ? $conf['hostname'] : gethostname(); $this->agent = isset($params['agent']) ? $params['agent'] : ''; $this->ticket = mt_rand(); }
public function __construct(array $params) { if (!isset($params['servers'])) { throw new InvalidArgumentException(__CLASS__ . ': missing servers parameter'); } $this->mServers = $params['servers']; $this->localDomain = isset($params['localDomain']) ? DatabaseDomain::newFromId($params['localDomain']) : DatabaseDomain::newUnspecified(); // In case a caller assumes that the domain ID is simply <db>-<prefix>, which is almost // always true, gracefully handle the case when they fail to account for escaping. if ($this->localDomain->getTablePrefix() != '') { $this->localDomainIdAlias = $this->localDomain->getDatabase() . '-' . $this->localDomain->getTablePrefix(); } else { $this->localDomainIdAlias = $this->localDomain->getDatabase(); } $this->mWaitTimeout = isset($params['waitTimeout']) ? $params['waitTimeout'] : 10; $this->mReadIndex = -1; $this->mConns = ['local' => [], 'foreignUsed' => [], 'foreignFree' => []]; $this->mLoads = []; $this->mWaitForPos = false; $this->mErrorConnection = false; $this->mAllowLagged = false; if (isset($params['readOnlyReason']) && is_string($params['readOnlyReason'])) { $this->readOnlyReason = $params['readOnlyReason']; } if (isset($params['loadMonitor'])) { $this->loadMonitorConfig = $params['loadMonitor']; } else { $this->loadMonitorConfig = ['class' => 'LoadMonitorNull']; } foreach ($params['servers'] as $i => $server) { $this->mLoads[$i] = $server['load']; if (isset($server['groupLoads'])) { foreach ($server['groupLoads'] as $group => $ratio) { if (!isset($this->mGroupLoads[$group])) { $this->mGroupLoads[$group] = []; } $this->mGroupLoads[$group][$i] = $ratio; } } } if (isset($params['srvCache'])) { $this->srvCache = $params['srvCache']; } else { $this->srvCache = new EmptyBagOStuff(); } if (isset($params['memCache'])) { $this->memCache = $params['memCache']; } else { $this->memCache = new EmptyBagOStuff(); } if (isset($params['wanCache'])) { $this->wanCache = $params['wanCache']; } else { $this->wanCache = WANObjectCache::newEmpty(); } $this->profiler = isset($params['profiler']) ? $params['profiler'] : null; if (isset($params['trxProfiler'])) { $this->trxProfiler = $params['trxProfiler']; } else { $this->trxProfiler = new TransactionProfiler(); } $this->errorLogger = isset($params['errorLogger']) ? $params['errorLogger'] : function (Exception $e) { trigger_error(get_class($e) . ': ' . $e->getMessage(), E_USER_WARNING); }; foreach (['replLogger', 'connLogger', 'queryLogger', 'perfLogger'] as $key) { $this->{$key} = isset($params[$key]) ? $params[$key] : new \Psr\Log\NullLogger(); } $this->host = isset($params['hostname']) ? $params['hostname'] : (gethostname() ?: 'unknown'); $this->cliMode = isset($params['cliMode']) ? $params['cliMode'] : PHP_SAPI === 'cli'; $this->agent = isset($params['agent']) ? $params['agent'] : ''; }
public function tablePrefix($prefix = null) { $old = $this->mTablePrefix; if ($prefix !== null) { $this->mTablePrefix = $prefix; $this->currentDomain = $this->mDBname != '' ? new DatabaseDomain($this->mDBname, null, $this->mTablePrefix) : DatabaseDomain::newUnspecified(); } return $old; }