ScopeResolver.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Url;
  7. /**
  8. * Class ScopeResolver
  9. *
  10. * URL scope resolver.
  11. */
  12. class ScopeResolver implements \Magento\Framework\Url\ScopeResolverInterface
  13. {
  14. /**
  15. * @var \Magento\Framework\App\ScopeResolverInterface
  16. */
  17. protected $scopeResolver;
  18. /**
  19. * @var null|string
  20. */
  21. protected $areaCode;
  22. /**
  23. * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
  24. * @param string|null $areaCode
  25. */
  26. public function __construct(\Magento\Framework\App\ScopeResolverInterface $scopeResolver, $areaCode = null)
  27. {
  28. $this->scopeResolver = $scopeResolver;
  29. $this->areaCode = $areaCode;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getScope($scopeId = null)
  35. {
  36. $scope = $this->scopeResolver->getScope($scopeId);
  37. if (!$scope instanceof \Magento\Framework\Url\ScopeInterface) {
  38. throw new \Magento\Framework\Exception\LocalizedException(
  39. new \Magento\Framework\Phrase('The scope object is invalid. Verify the scope object and try again.')
  40. );
  41. }
  42. return $scope;
  43. }
  44. /**
  45. * Retrieve array of URL scopes.
  46. *
  47. * @return \Magento\Framework\Url\ScopeInterface[]
  48. */
  49. public function getScopes()
  50. {
  51. return $this->scopeResolver->getScopes();
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function getAreaCode()
  57. {
  58. return $this->areaCode;
  59. }
  60. }