MediaWiki  REL1_31
TestBagOStuff.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Session;
4 
9 
10  public function __construct() {
11  parent::__construct( new \HashBagOStuff );
12  }
13 
18  public function setSessionData( $id, array $data ) {
19  $this->setSession( $id, [ 'data' => $data ] );
20  }
21 
26  public function setSessionMeta( $id, array $metadata ) {
27  $this->setSession( $id, [ 'metadata' => $metadata ] );
28  }
29 
34  public function setSession( $id, array $blob ) {
35  $blob += [
36  'data' => [],
37  'metadata' => [],
38  ];
39  $blob['metadata'] += [
40  'userId' => 0,
41  'userName' => null,
42  'userToken' => null,
43  'provider' => 'DummySessionProvider',
44  ];
45 
46  $this->setRawSession( $id, $blob );
47  }
48 
53  public function setRawSession( $id, $blob ) {
54  $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
55  $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
56  }
57 
62  public function getSession( $id ) {
63  return $this->get( $this->makeKey( 'MWSession', $id ) );
64  }
65 
70  public function getSessionFromBackend( $id ) {
71  return $this->backend->get( $this->makeKey( 'MWSession', $id ) );
72  }
73 
77  public function deleteSession( $id ) {
78  $this->delete( $this->makeKey( 'MWSession', $id ) );
79  }
80 
81 }
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.
CachedBagOStuff\makeKey
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
Definition: CachedBagOStuff.php:89
MediaWiki\Session\TestBagOStuff\setSessionData
setSessionData( $id, array $data)
Definition: TestBagOStuff.php:18
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWiki\Session\TestBagOStuff\getSession
getSession( $id)
Definition: TestBagOStuff.php:62
MediaWiki\Session\TestBagOStuff\setSessionMeta
setSessionMeta( $id, array $metadata)
Definition: TestBagOStuff.php:26
$blob
$blob
Definition: testCompression.php:65
MediaWiki\Session\TestBagOStuff\__construct
__construct()
Definition: TestBagOStuff.php:10
MediaWiki\Session
Definition: BotPasswordSessionProvider.php:24
MediaWiki\Session\TestBagOStuff\setSession
setSession( $id, array $blob)
Definition: TestBagOStuff.php:34
MediaWiki\Session\TestBagOStuff
BagOStuff with utility functions for MediaWiki\\Session\\* testing.
Definition: TestBagOStuff.php:8
CachedBagOStuff
Wrapper around a BagOStuff that caches data in memory.
Definition: CachedBagOStuff.php:36
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:434
MediaWiki\Session\TestBagOStuff\getSessionFromBackend
getSessionFromBackend( $id)
Definition: TestBagOStuff.php:70
MediaWiki\Session\TestBagOStuff\deleteSession
deleteSession( $id)
Definition: TestBagOStuff.php:77
MediaWiki\Session\TestBagOStuff\setRawSession
setRawSession( $id, $blob)
Definition: TestBagOStuff.php:53