ScopeValidator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model;
  7. use Magento\Framework\App\ScopeValidatorInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\Exception\NoSuchEntityException;
  10. use Magento\Framework\App\ScopeResolverPool;
  11. class ScopeValidator implements ScopeValidatorInterface
  12. {
  13. /**
  14. * @var ScopeResolverPool
  15. */
  16. protected $scopeResolverPool;
  17. /**
  18. * @param ScopeResolverPool $scopeResolverPool
  19. */
  20. public function __construct(ScopeResolverPool $scopeResolverPool)
  21. {
  22. $this->scopeResolverPool = $scopeResolverPool;
  23. }
  24. /**
  25. * @inheritDoc
  26. */
  27. public function isValidScope($scope, $scopeId = null)
  28. {
  29. if ($scope == ScopeConfigInterface::SCOPE_TYPE_DEFAULT && !$scopeId) {
  30. return true;
  31. }
  32. try {
  33. $scopeResolver = $this->scopeResolverPool->get($scope);
  34. if (!$scopeResolver->getScope($scopeId)->getId()) {
  35. return false;
  36. }
  37. } catch (\InvalidArgumentException $e) {
  38. return false;
  39. } catch (NoSuchEntityException $e) {
  40. return false;
  41. }
  42. return true;
  43. }
  44. }