Add "generic" key methods for quickly deriving keys from key component lists in a bijective manor. This is useful for BagOStuff classes that wrap other BagOStuff instances or for parsing keys to get stats. Make the proxy BagOStuff classes (ReplicatedBagOStuff, MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys so that they can convert to appropriate keys when making backing cache instance method calls. Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff, RedisBagOStuff, and RESTBagOStuff use "generic" keys rather than those of MediumSpecificBagOStuff::makeKeyInternal(). This lets proxy BagOStuff classes bypass key conversions when used with instances of these classes as backing stores. Also: * Fix missing incr(), incrWithInit(), and decr() return values in MultiWriteBagOStuff. * Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and CachedBagOStuff use similar backend method forwarding styles by using a new BagOStuff method. * Improved various related bits of documentation. Bug: T250239 Bug: T235705 Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Session;
|
|
|
|
use CachedBagOStuff;
|
|
use HashBagOStuff;
|
|
use RequestContext;
|
|
|
|
/**
|
|
* BagOStuff with utility functions for MediaWiki\\Session\\* testing
|
|
*/
|
|
class TestBagOStuff extends CachedBagOStuff {
|
|
|
|
public function __construct() {
|
|
parent::__construct( new HashBagOStuff );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @param array $data Session data
|
|
*/
|
|
public function setSessionData( $id, array $data ) {
|
|
$this->setSession( $id, [ 'data' => $data ] );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @param array $metadata Session metadata
|
|
*/
|
|
public function setSessionMeta( $id, array $metadata ) {
|
|
$this->setSession( $id, [ 'metadata' => $metadata ] );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @param array $blob Session metadata and data
|
|
*/
|
|
public function setSession( $id, array $blob ) {
|
|
$blob += [
|
|
'data' => [],
|
|
'metadata' => [],
|
|
];
|
|
$blob['metadata'] += [
|
|
'userId' => 0,
|
|
'userName' => null,
|
|
'userToken' => null,
|
|
'provider' => 'DummySessionProvider',
|
|
];
|
|
|
|
$this->setRawSession( $id, $blob );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @param array|mixed $blob Session metadata and data
|
|
*/
|
|
public function setRawSession( $id, $blob ) {
|
|
$expiry = RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
|
|
$this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @return mixed
|
|
*/
|
|
public function getSession( $id ) {
|
|
return $this->get( $this->makeKey( 'MWSession', $id ) );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
* @return mixed
|
|
*/
|
|
public function getSessionFromBackend( $id ) {
|
|
return $this->store->get( $this->makeKey( 'MWSession', $id ) );
|
|
}
|
|
|
|
/**
|
|
* @param string $id Session ID
|
|
*/
|
|
public function deleteSession( $id ) {
|
|
$this->delete( $this->makeKey( 'MWSession', $id ) );
|
|
}
|
|
|
|
}
|