AdminSessionUserContext.php 981 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\User\Model\Authorization;
  7. use Magento\Authorization\Model\UserContextInterface;
  8. use Magento\Backend\Model\Auth\Session as AdminSession;
  9. /**
  10. * Session-based admin user context
  11. */
  12. class AdminSessionUserContext implements UserContextInterface
  13. {
  14. /**
  15. * @var AdminSession
  16. */
  17. protected $_adminSession;
  18. /**
  19. * Initialize dependencies.
  20. *
  21. * @param AdminSession $adminSession
  22. */
  23. public function __construct(AdminSession $adminSession)
  24. {
  25. $this->_adminSession = $adminSession;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function getUserId()
  31. {
  32. return $this->_adminSession->hasUser() ? (int)$this->_adminSession->getUser()->getId() : null;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getUserType()
  38. {
  39. return UserContextInterface::USER_TYPE_ADMIN;
  40. }
  41. }