Source.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Scope;
  7. use Magento\Framework\App\ScopeResolverPool;
  8. use Magento\Framework\Option\ArrayInterface;
  9. class Source implements ArrayInterface
  10. {
  11. /**
  12. * @var ScopeResolverPool
  13. */
  14. protected $scopeResolverPool;
  15. /**
  16. * @var string
  17. */
  18. protected $scope;
  19. /**
  20. * @param ScopeResolverPool $scopeResolverPool
  21. * @param string $scope
  22. */
  23. public function __construct(
  24. ScopeResolverPool $scopeResolverPool,
  25. $scope
  26. ) {
  27. $this->scopeResolverPool = $scopeResolverPool;
  28. $this->scope = $scope;
  29. }
  30. /**
  31. * Return array of scope names
  32. *
  33. * @return array
  34. */
  35. public function toOptionArray()
  36. {
  37. $scopes = $this->scopeResolverPool->get($this->scope)->getScopes();
  38. $array = [];
  39. foreach ($scopes as $scope) {
  40. $array[] = ['value' => $scope->getId(), 'label' => $scope->getName()];
  41. }
  42. return $array;
  43. }
  44. }