Group.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model\Resolver;
  7. use Magento\Framework\App\ScopeInterface;
  8. use Magento\Framework\App\ScopeResolverInterface;
  9. use Magento\Framework\Exception\State\InitException;
  10. use Magento\Store\Model\StoreManagerInterface;
  11. class Group implements ScopeResolverInterface
  12. {
  13. /**
  14. * @var StoreManagerInterface
  15. */
  16. protected $storeManager;
  17. /**
  18. * @param StoreManagerInterface $storeManager
  19. */
  20. public function __construct(StoreManagerInterface $storeManager)
  21. {
  22. $this->storeManager = $storeManager;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. * @throws InitException
  27. */
  28. public function getScope($scopeId = null)
  29. {
  30. $scope = $this->storeManager->getGroup($scopeId);
  31. if (!$scope instanceof ScopeInterface) {
  32. throw new InitException(__('The scope object is invalid. Verify the scope object and try again.'));
  33. }
  34. return $scope;
  35. }
  36. /**
  37. * Retrieve a list of available groups
  38. *
  39. * @return \Magento\Store\Model\Group[]
  40. */
  41. public function getScopes()
  42. {
  43. return $this->storeManager->getGroups();
  44. }
  45. }