ParamOverriderCustomerId.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Controller\Rest;
  7. use Magento\Authorization\Model\UserContextInterface;
  8. use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface;
  9. /**
  10. * Replaces a "%customer_id%" value with the real customer id
  11. */
  12. class ParamOverriderCustomerId implements ParamOverriderInterface
  13. {
  14. /**
  15. * @var UserContextInterface
  16. */
  17. private $userContext;
  18. /**
  19. * Constructs an object to override the customer ID parameter on a request.
  20. *
  21. * @param UserContextInterface $userContext
  22. */
  23. public function __construct(UserContextInterface $userContext)
  24. {
  25. $this->userContext = $userContext;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function getOverriddenValue()
  31. {
  32. if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
  33. return $this->userContext->getUserId();
  34. }
  35. return null;
  36. }
  37. }