CustomerSessionUserContext.php 973 B

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