AccountSwitcherInterface.php 916 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Drupal\Core\Session;
  3. /**
  4. * Defines an interface for a service for safe account switching.
  5. *
  6. * @ingroup user_api
  7. */
  8. interface AccountSwitcherInterface {
  9. /**
  10. * Safely switches to another account.
  11. *
  12. * Each invocation of AccountSwitcherInterface::switchTo() must be
  13. * matched by a corresponding invocation of
  14. * AccountSwitcherInterface::switchBack() in the same function.
  15. *
  16. * @param \Drupal\Core\Session\AccountInterface $account
  17. * The account to switch to.
  18. *
  19. * @return \Drupal\Core\Session\AccountSwitcherInterface
  20. * $this.
  21. */
  22. public function switchTo(AccountInterface $account);
  23. /**
  24. * Reverts to a previous account after switching.
  25. *
  26. * @return \Drupal\Core\Session\AccountSwitcherInterface
  27. * $this.
  28. *
  29. * @throws \RuntimeException
  30. * When there are no more account switches to revert.
  31. */
  32. public function switchBack();
  33. }