ScopeResolverPool.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App;
  7. /**
  8. * Provider of scope resolvers by type
  9. */
  10. class ScopeResolverPool
  11. {
  12. /**
  13. * @var array
  14. */
  15. protected $_scopeResolvers = [];
  16. /**
  17. * @param \Magento\Framework\App\ScopeResolverInterface[] $scopeResolvers
  18. */
  19. public function __construct(
  20. array $scopeResolvers = []
  21. ) {
  22. $this->_scopeResolvers = $scopeResolvers;
  23. }
  24. /**
  25. * Retrieve reader by scope type
  26. *
  27. * @param string $scopeType
  28. * @throws \InvalidArgumentException
  29. * @return \Magento\Framework\App\ScopeResolverInterface
  30. */
  31. public function get($scopeType)
  32. {
  33. if (!isset($this->_scopeResolvers[$scopeType]) ||
  34. !($this->_scopeResolvers[$scopeType] instanceof \Magento\Framework\App\ScopeResolverInterface)
  35. ) {
  36. throw new \InvalidArgumentException("Invalid scope type '{$scopeType}'");
  37. }
  38. return $this->_scopeResolvers[$scopeType];
  39. }
  40. }