Ejemplo n.º 1
0
 /**
  * Constructor. Parameters are:
  *   - writeFactory : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff.
  *                    This object will be used for writes (e.g. the master DB).
  *   - readFactory  : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff.
  *                    This object will be used for reads (e.g. a slave DB).
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (!isset($params['writeFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "writeFactory" parameter is required');
     }
     if (!isset($params['readFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "readFactory" parameter is required');
     }
     $this->writeStore = $params['writeFactory'] instanceof BagOStuff ? $params['writeFactory'] : ObjectFactory::getObjectFromSpec($params['writeFactory']);
     $this->readStore = $params['readFactory'] instanceof BagOStuff ? $params['readFactory'] : ObjectFactory::getObjectFromSpec($params['readFactory']);
 }
Ejemplo n.º 2
0
 /**
  * @covers ObjectFactory::getObjectFromSpec
  */
 public function testClosureExpansionEnabled()
 {
     $obj = ObjectFactory::getObjectFromSpec(array('class' => 'ObjectFactoryTest_Fixture', 'args' => array(function () {
         return 'unwrapped';
     }), 'closure_expansion' => true));
     $this->assertInternalType('string', $obj->args[0]);
     $this->assertSame('unwrapped', $obj->args[0]);
     $obj = ObjectFactory::getObjectFromSpec(array('class' => 'ObjectFactoryTest_Fixture', 'args' => array(function () {
         return 'unwrapped';
     })));
     $this->assertInternalType('string', $obj->args[0]);
     $this->assertSame('unwrapped', $obj->args[0]);
 }
Ejemplo n.º 3
0
 /**
  * Constructor. Parameters are:
  *   - writeFactory : ObjectFactory::getObjectFromSpec array yeilding BagOStuff.
  *                    This object will be used for writes (e.g. the master DB).
  *   - readFactory  : ObjectFactory::getObjectFromSpec array yeilding BagOStuff.
  *                    This object will be used for reads (e.g. a replica DB).
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (!isset($params['writeFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "writeFactory" parameter is required');
     }
     if (!isset($params['readFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "readFactory" parameter is required');
     }
     $opts = ['reportDupes' => false];
     // redundant
     $this->writeStore = $params['writeFactory'] instanceof BagOStuff ? $params['writeFactory'] : ObjectFactory::getObjectFromSpec($opts + $params['writeFactory']);
     $this->readStore = $params['readFactory'] instanceof BagOStuff ? $params['readFactory'] : ObjectFactory::getObjectFromSpec($opts + $params['readFactory']);
     $this->attrMap = $this->mergeFlagMaps([$this->readStore, $this->writeStore]);
 }
Ejemplo n.º 4
0
 /**
  * Fetch a CentralIdLookup
  * @param string|null $providerId Provider ID from $wgCentralIdLookupProviders
  * @return CentralIdLookup|null
  */
 public static function factory($providerId = null)
 {
     global $wgCentralIdLookupProviders, $wgCentralIdLookupProvider;
     if ($providerId === null) {
         $providerId = $wgCentralIdLookupProvider;
     }
     if (!array_key_exists($providerId, self::$instances)) {
         self::$instances[$providerId] = null;
         if (isset($wgCentralIdLookupProviders[$providerId])) {
             $provider = ObjectFactory::getObjectFromSpec($wgCentralIdLookupProviders[$providerId]);
             if ($provider instanceof CentralIdLookup) {
                 $provider->providerId = $providerId;
                 self::$instances[$providerId] = $provider;
             }
         }
     }
     return self::$instances[$providerId];
 }
Ejemplo n.º 5
0
 /**
  * @covers ObjectFactory::getObjectFromSpec
  */
 public function testClosureExpansionEnabled()
 {
     $obj = ObjectFactory::getObjectFromSpec(['class' => 'ObjectFactoryTestFixture', 'args' => [function () {
         return 'unwrapped';
     }], 'calls' => ['setter' => [function () {
         return 'unwrapped';
     }]], 'closure_expansion' => true]);
     $this->assertInternalType('string', $obj->args[0]);
     $this->assertSame('unwrapped', $obj->args[0]);
     $this->assertInternalType('string', $obj->setterArgs[0]);
     $this->assertSame('unwrapped', $obj->setterArgs[0]);
     $obj = ObjectFactory::getObjectFromSpec(['class' => 'ObjectFactoryTestFixture', 'args' => [function () {
         return 'unwrapped';
     }], 'calls' => ['setter' => [function () {
         return 'unwrapped';
     }]]]);
     $this->assertInternalType('string', $obj->args[0]);
     $this->assertSame('unwrapped', $obj->args[0]);
     $this->assertInternalType('string', $obj->setterArgs[0]);
     $this->assertSame('unwrapped', $obj->setterArgs[0]);
 }
Ejemplo n.º 6
0
 /**
  * $params include:
  *   - caches: A numbered array of either ObjectFactory::getObjectFromSpec
  *      arrays yeilding BagOStuff objects or direct BagOStuff objects.
  *      If using the former, the 'args' field *must* be set.
  *      The first cache is the primary one, being the first to
  *      be read in the fallback chain. Writes happen to all stores
  *      in the order they are defined. However, lock()/unlock() calls
  *      only use the primary store.
  *   - replication: Either 'sync' or 'async'. This controls whether writes
  *      to secondary stores are deferred when possible. Async writes
  *      require setting 'asyncHandler'. HHVM register_postsend_function() function.
  *      Async writes can increase the chance of some race conditions
  *      or cause keys to expire seconds later than expected. It is
  *      safe to use for modules when cached values: are immutable,
  *      invalidation uses logical TTLs, invalidation uses etag/timestamp
  *      validation against the DB, or merge() is used to handle races.
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($params['caches']) || !is_array($params['caches'])) {
         throw new InvalidArgumentException(__METHOD__ . ': "caches" parameter must be an array of caches');
     }
     $this->caches = [];
     foreach ($params['caches'] as $cacheInfo) {
         if ($cacheInfo instanceof BagOStuff) {
             $this->caches[] = $cacheInfo;
         } else {
             if (!isset($cacheInfo['args'])) {
                 // B/C for when $cacheInfo was for ObjectCache::newFromParams().
                 // Callers intenting this to be for ObjectFactory::getObjectFromSpec
                 // should have set "args" per the docs above. Doings so avoids extra
                 // (likely harmless) params (factory/class/calls) ending up in "args".
                 $cacheInfo['args'] = [$cacheInfo];
             }
             $this->caches[] = ObjectFactory::getObjectFromSpec($cacheInfo);
         }
     }
     $this->asyncWrites = isset($params['replication']) && $params['replication'] === 'async' && is_callable($this->asyncHandler);
 }
Ejemplo n.º 7
0
 /**
  * Get the available SessionProviders
  * @return SessionProvider[]
  */
 protected function getProviders()
 {
     if ($this->sessionProviders === null) {
         $this->sessionProviders = array();
         foreach ($this->config->get('SessionProviders') as $spec) {
             $provider = \ObjectFactory::getObjectFromSpec($spec);
             $provider->setLogger($this->logger);
             $provider->setConfig($this->config);
             $provider->setManager($this);
             if (isset($this->sessionProviders[(string) $provider])) {
                 throw new \UnexpectedValueException("Duplicate provider name \"{$provider}\"");
             }
             $this->sessionProviders[(string) $provider] = $provider;
         }
     }
     return $this->sessionProviders;
 }
Ejemplo n.º 8
0
 /**
  * Find the object with a given name and return it (or NULL)
  *
  * @param string $name Special page name, may be localised and/or an alias
  * @return SpecialPage|null SpecialPage object or null if the page doesn't exist
  */
 public static function getPage($name)
 {
     list($realName, ) = self::resolveAlias($name);
     if (isset(self::$pageObjectCache[$realName])) {
         return self::$pageObjectCache[$realName];
     }
     $specialPageList = self::getPageList();
     if (isset($specialPageList[$realName])) {
         $rec = $specialPageList[$realName];
         if (is_callable($rec)) {
             // Use callback to instantiate the special page
             $page = call_user_func($rec);
         } elseif (is_string($rec)) {
             $className = $rec;
             $page = new $className();
         } elseif (is_array($rec)) {
             $className = array_shift($rec);
             // @deprecated, officially since 1.18, unofficially since forever
             wfDeprecated("Array syntax for \$wgSpecialPages is deprecated ({$className}), " . "define a subclass of SpecialPage instead.", '1.18');
             $page = ObjectFactory::getObjectFromSpec(['class' => $className, 'args' => $rec, 'closure_expansion' => false]);
         } elseif ($rec instanceof SpecialPage) {
             $page = $rec;
             // XXX: we should deep clone here
         } else {
             $page = null;
         }
         self::$pageObjectCache[$realName] = $page;
         if ($page instanceof SpecialPage) {
             return $page;
         } else {
             // It's not a classname, nor a callback, nor a legacy constructor array,
             // nor a special page object. Give up.
             wfLogWarning("Cannot instantiate special page {$realName}: bad spec!");
             return null;
         }
     } else {
         return null;
     }
 }
Ejemplo n.º 9
0
 /**
  * @covers ObjectFactory::getObjectFromSpec
  * @dataProvider provideConstructClassInstance
  */
 public function testGetObjectFromClass($args)
 {
     $obj = ObjectFactory::getObjectFromSpec(['class' => 'ObjectFactoryTestFixture', 'args' => $args]);
     $this->assertSame($args, $obj->args);
 }
Ejemplo n.º 10
0
 /**
  * Create a new object to replace this stub object.
  * @return object
  */
 public function _newObject()
 {
     $params = $this->factory ? ['factory' => $this->factory] : ['class' => $this->class];
     return ObjectFactory::getObjectFromSpec($params + ['args' => $this->params, 'closure_expansion' => false]);
 }
Ejemplo n.º 11
0
 /**
  * Create a new object to replace this stub object.
  * @return object
  */
 public function _newObject()
 {
     return ObjectFactory::getObjectFromSpec(array('class' => $this->class, 'args' => $this->params, 'closure_expansion' => false));
 }
Ejemplo n.º 12
0
 /**
  * @param string $class
  * @param array $args
  * @return object
  * @deprecated 1.25 Use ObjectFactory::getObjectFromSpec() instead
  */
 public static function newObj($class, $args = array())
 {
     wfDeprecated(__METHOD__, '1.25');
     return ObjectFactory::getObjectFromSpec(array('class' => $class, 'args' => $args, 'closure_expansion' => false));
 }
Ejemplo n.º 13
0
// five edits
// Caching
$wgObjectCaches['redis'] = array('class' => 'RedisBagOStuff', 'servers' => array('127.0.0.1:6379'), 'persistent' => true);
$wgMainCacheType = 'redis';
// Avoid user request serialization and other slowness
$wgSessionCacheType = 'redis';
$wgSessionsInObjectCache = true;
// Jobqueue
$wgJobTypeConf['default'] = array('class' => 'JobQueueRedis', 'daemonized' => true, 'redisServer' => '127.0.0.1', 'redisConfig' => array('connectTimeout' => 2, 'compression' => 'gzip'));
$wgJobQueueAggregator = array('class' => 'JobQueueAggregatorRedis', 'redisServers' => array('127.0.0.1'), 'redisConfig' => array('connectTimeout' => 2));
$wgLegacyJavaScriptGlobals = false;
$wgEnableJavaScriptTest = true;
require_once __DIR__ . '/settings.d/wikis/CommonSettings.php';
// XXX: Is this a bug in core? (ori-l, 27-Aug-2013)
$wgHooks['GetIP'][] = function (&$ip) {
    if (PHP_SAPI === 'cli') {
        $ip = '127.0.0.1';
    }
    return true;
};
// Execute all jobs via standalone jobrunner service rather than
// piggybacking them on web requests.
$wgJobRunRate = 0;
// Bug 73037: handmade gzipping sometimes makes error messages impossible to see in HHVM
$wgDisableOutputCompression = true;
// Allow 'vagrant' password.
$wgPasswordPolicy['policies']['sysop']['MinimalPasswordLength'] = 7;
$wgPasswordPolicy['policies']['bureaucrat']['MinimalPasswordLength'] = 7;
// Ensure that full LoggerFactory configuration is applied
MediaWiki\Logger\LoggerFactory::registerProvider(ObjectFactory::getObjectFromSpec($wgMWLoggerDefaultSpi));
Ejemplo n.º 14
0
 /**
  * Create an array of AuthenticationProviders from an array of ObjectFactory specs
  * @param string $class
  * @param array[] $specs
  * @return AuthenticationProvider[]
  */
 protected function providerArrayFromSpecs($class, array $specs)
 {
     $i = 0;
     foreach ($specs as &$spec) {
         $spec = ['sort2' => $i++] + $spec + ['sort' => 0];
     }
     unset($spec);
     usort($specs, function ($a, $b) {
         return (int) $a['sort'] - (int) $b['sort'] ?: $a['sort2'] - $b['sort2'];
     });
     $ret = [];
     foreach ($specs as $spec) {
         $provider = \ObjectFactory::getObjectFromSpec($spec);
         if (!$provider instanceof $class) {
             throw new \RuntimeException("Expected instance of {$class}, got " . get_class($provider));
         }
         $provider->setLogger($this->logger);
         $provider->setManager($this);
         $provider->setConfig($this->config);
         $id = $provider->getUniqueId();
         if (isset($this->allAuthenticationProviders[$id])) {
             throw new \RuntimeException("Duplicate specifications for id {$id} (classes " . get_class($provider) . ' and ' . get_class($this->allAuthenticationProviders[$id]) . ')');
         }
         $this->allAuthenticationProviders[$id] = $provider;
         $ret[$id] = $provider;
     }
     return $ret;
 }