AccountProxyInterface.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Core\Session;
  3. /**
  4. * Defines an interface for a service which has the current account stored.
  5. *
  6. * It is generally more useful to use \Drupal\Core\Session\AccountInterface
  7. * unless one specifically needs the proxying features of this interface.
  8. *
  9. * @see \Drupal\Core\Session\AccountInterface
  10. *
  11. * @ingroup user_api
  12. */
  13. interface AccountProxyInterface extends AccountInterface {
  14. /**
  15. * Sets the currently wrapped account.
  16. *
  17. * Setting the current account is highly discouraged! Instead, make sure to
  18. * inject the desired user object into the dependent code directly.
  19. *
  20. * A preferable method of account impersonation is to use
  21. * \Drupal\Core\Session\AccountSwitcherInterface::switchTo() and
  22. * \Drupal\Core\Session\AccountSwitcherInterface::switchBack().
  23. *
  24. * @param \Drupal\Core\Session\AccountInterface $account
  25. * The current account.
  26. */
  27. public function setAccount(AccountInterface $account);
  28. /**
  29. * Gets the currently wrapped account.
  30. *
  31. * @return \Drupal\Core\Session\AccountInterface
  32. * The current account.
  33. */
  34. public function getAccount();
  35. /**
  36. * Sets the id of the initial account.
  37. *
  38. * Never use this method, its sole purpose is to work around weird effects
  39. * during mid-request container rebuilds.
  40. *
  41. * @param int $account_id
  42. * The id of the initial account.
  43. */
  44. public function setInitialAccountId($account_id);
  45. }