Drupal 8  8.0.2
AccountSwitcher Class Reference
Inheritance diagram for AccountSwitcher:

Public Member Functions

 __construct (AccountProxyInterface $current_user, WriteSafeSessionHandlerInterface $write_safe_handler)
 
 switchTo (AccountInterface $account)
 
 switchBack ()
 

Protected Attributes

 $accountStack = array()
 
 $currentUser = array()
 
 $writeSafeHandler
 
 $originalSessionSaving
 

Detailed Description

An implementation of AccountSwitcherInterface.

This allows for safe switching of user accounts by ensuring that session data for one user is not leaked in to others. It also provides a stack that allows reverting to a previous user after switching.

Constructor & Destructor Documentation

__construct ( AccountProxyInterface  $current_user,
WriteSafeSessionHandlerInterface  $write_safe_handler 
)

Constructs a new AccountSwitcher.

Parameters
\Drupal\Core\Session\AccountProxyInterface$current_userThe current user service.
\Drupal\Core\Session\WriteSafeSessionHandlerInterface$write_safe_handlerThe write-safe session handler.

References Drupal\currentUser().

Here is the call graph for this function:

Member Function Documentation

switchBack ( )

{Reverts to a previous account after switching.

Returns
$this.
Exceptions
\RuntimeExceptionWhen there are no more account switches to revert.
}

Implements AccountSwitcherInterface.

References Drupal\currentUser().

Here is the call graph for this function:

switchTo ( AccountInterface  $account)

{Safely switches to another account.Each invocation of AccountSwitcherInterface::switchTo() must be matched by a corresponding invocation of AccountSwitcherInterface::switchBack() in the same function.

Parameters
\Drupal\Core\Session\AccountInterface$accountThe account to switch to.
Returns
$this.
}

Implements AccountSwitcherInterface.

References Drupal\currentUser().

Here is the call graph for this function:


The documentation for this class was generated from the following file: