3 namespace MediaWiki\Session
;
6 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
8 class TestBagOStuff
extends \CachedBagOStuff
{
10 public function __construct() {
11 parent
::__construct( new \HashBagOStuff
);
15 * @param string $id Session ID
16 * @param array $data Session data
17 * @param int $expiry Expiry
18 * @param User $user User for metadata
20 public function setSessionData( $id, array $data, $expiry = 0, User
$user = null ) {
21 $this->setSession( $id, [ 'data' => $data ], $expiry, $user );
25 * @param string $id Session ID
26 * @param array $metadata Session metadata
27 * @param int $expiry Expiry
29 public function setSessionMeta( $id, array $metadata, $expiry = 0 ) {
30 $this->setSession( $id, [ 'metadata' => $metadata ], $expiry );
34 * @param string $id Session ID
35 * @param array $blob Session metadata and data
36 * @param int $expiry Expiry
37 * @param User $user User for metadata
39 public function setSession( $id, array $blob, $expiry = 0, User
$user = null ) {
44 $blob['metadata'] +
= [
45 'userId' => $user ?
$user->getId() : 0,
46 'userName' => $user ?
$user->getName() : null,
47 'userToken' => $user ?
$user->getToken( true ) : null,
48 'provider' => 'DummySessionProvider',
51 $this->setRawSession( $id, $blob, $expiry, $user );
55 * @param string $id Session ID
56 * @param array|mixed $blob Session metadata and data
57 * @param int $expiry Expiry
59 public function setRawSession( $id, $blob, $expiry = 0 ) {
61 $expiry = \RequestContext
::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
64 $this->set( wfMemcKey( 'MWSession', $id ), $blob, $expiry );
68 * @param string $id Session ID
71 public function getSession( $id ) {
72 return $this->get( wfMemcKey( 'MWSession', $id ) );
76 * @param string $id Session ID
79 public function getSessionFromBackend( $id ) {
80 return $this->backend
->get( wfMemcKey( 'MWSession', $id ) );
84 * @param string $id Session ID
86 public function deleteSession( $id ) {
87 $this->delete( wfMemcKey( 'MWSession', $id ) );