/** * @see FileBackend::__construct() * Additional $config params include: * - wanCache : WANObjectCache object to use for persistent caching. * - mimeCallback : Callback that takes (storage path, content, file system path) and * returns the MIME type of the file or 'unknown/unknown'. The file * system path parameter should be used if the content one is null. * * @param array $config */ public function __construct(array $config) { parent::__construct($config); $this->mimeCallback = isset($config['mimeCallback']) ? $config['mimeCallback'] : null; $this->memCache = WANObjectCache::newEmpty(); // disabled by default $this->cheapCache = new ProcessCacheLRU(self::CACHE_CHEAP_SIZE); $this->expensiveCache = new ProcessCacheLRU(self::CACHE_EXPENSIVE_SIZE); }
/** * @see FileBackend::__construct() * Additional $config params include: * - wanCache : WANOBjectCache object to use for persistent caching. * - mimeCallback : Callback that takes (storage path, content, file system path) and * returns the MIME type of the file or 'unknown/unknown'. The file * system path parameter should be used if the content one is null. * * @param array $config */ public function __construct(array $config) { parent::__construct($config); $this->mimeCallback = isset($config['mimeCallback']) ? $config['mimeCallback'] : function ($storagePath, $content, $fsPath) { // @todo handle the case of extension-less files using the contents return StreamFile::contentTypeFromPath($storagePath) ?: 'unknown/unknown'; }; $this->memCache = WANObjectCache::newEmpty(); // disabled by default $this->cheapCache = new ProcessCacheLRU(self::CACHE_CHEAP_SIZE); $this->expensiveCache = new ProcessCacheLRU(self::CACHE_EXPENSIVE_SIZE); }
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 testArrayStorage() { $dewiki = ['iw_prefix' => 'de', 'iw_url' => 'http://de.wikipedia.org/wiki/', 'iw_local' => 1]; $zzwiki = ['iw_prefix' => 'zz', 'iw_url' => 'http://zzwiki.org/wiki/', 'iw_local' => 0]; $hash = $this->populateHash('en', [$dewiki], [$zzwiki]); $lookup = new \MediaWiki\Interwiki\ClassicInterwikiLookup(Language::factory('en'), WANObjectCache::newEmpty(), 60 * 60, $hash, 3, 'en'); $this->assertEquals([$dewiki, $zzwiki], $lookup->getAllPrefixes(), 'getAllPrefixes()'); $this->assertTrue($lookup->isValidInterwiki('de'), 'known prefix is valid'); $this->assertTrue($lookup->isValidInterwiki('zz'), 'known prefix is valid'); $interwiki = $lookup->fetch('de'); $this->assertInstanceOf('Interwiki', $interwiki); $this->assertSame('http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL'); $this->assertSame(true, $interwiki->isLocal(), 'isLocal'); $interwiki = $lookup->fetch('zz'); $this->assertInstanceOf('Interwiki', $interwiki); $this->assertSame('http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL'); $this->assertSame(false, $interwiki->isLocal(), 'isLocal'); }