MediaWiki  1.27.2
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 
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( wfMemcKey( 'MWSession', $id ), $blob, $expiry );
65  }
66 
71  public function getSession( $id ) {
72  return $this->get( wfMemcKey( 'MWSession', $id ) );
73  }
74 
79  public function getSessionFromBackend( $id ) {
80  return $this->backend->get( wfMemcKey( 'MWSession', $id ) );
81  }
82 
86  public function deleteSession( $id ) {
87  $this->delete( wfMemcKey( 'MWSession', $id ) );
88  }
89 
90 }
setSessionData($id, array $data, $expiry=0, User $user=null)
the array() calling protocol came about after MediaWiki 1.4rc1.
BagOStuff with utility functions for MediaWiki\\Session\\* testing.
set($key, $value, $exptime=0, $flags=0)
static getMain()
Static methods.
setSessionMeta($id, array $metadata, $expiry=0)
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
setSession($id, array $blob, $expiry=0, User $user=null)
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:35
Wrapper around a BagOStuff that caches data in memory.
wfMemcKey()
Make a cache key for the local wiki.
setRawSession($id, $blob, $expiry=0)