MediaWiki REL1_30
TestBagOStuff.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Session;
4
9
10 public function __construct() {
11 parent::__construct( new \HashBagOStuff );
12 }
13
20 public function setSessionData( $id, array $data, $expiry = 0, User $user = null ) {
21 $this->setSession( $id, [ 'data' => $data ], $expiry, $user );
22 }
23
29 public function setSessionMeta( $id, array $metadata, $expiry = 0 ) {
30 $this->setSession( $id, [ 'metadata' => $metadata ], $expiry );
31 }
32
39 public function setSession( $id, array $blob, $expiry = 0, User $user = null ) {
40 $blob += [
41 'data' => [],
42 'metadata' => [],
43 ];
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',
49 ];
50
51 $this->setRawSession( $id, $blob, $expiry, $user );
52 }
53
59 public function setRawSession( $id, $blob, $expiry = 0 ) {
60 if ( $expiry <= 0 ) {
61 $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
62 }
63
64 $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
65 }
66
71 public function getSession( $id ) {
72 return $this->get( $this->makeKey( 'MWSession', $id ) );
73 }
74
79 public function getSessionFromBackend( $id ) {
80 return $this->backend->get( $this->makeKey( 'MWSession', $id ) );
81 }
82
86 public function deleteSession( $id ) {
87 $this->delete( $this->makeKey( 'MWSession', $id ) );
88 }
89
90}
Wrapper around a BagOStuff that caches data in memory.
makeKey()
Make a cache key, scoped to this instance's keyspace.
Simple store for keeping values in an associative array for the current process.
BagOStuff with utility functions for MediaWiki\\Session\\* testing.
setSession( $id, array $blob, $expiry=0, User $user=null)
setSessionData( $id, array $data, $expiry=0, User $user=null)
setRawSession( $id, $blob, $expiry=0)
setSessionMeta( $id, array $metadata, $expiry=0)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51