Validator.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model\Config;
  7. use Magento\Framework\App\DeploymentConfig\ValidatorInterface;
  8. use Magento\Store\Model\ScopeInterface;
  9. /**
  10. * Validates that scopes data contain correct values
  11. */
  12. class Validator implements ValidatorInterface
  13. {
  14. /**
  15. * Checks that scopes data contain at least one not admin website, group and store
  16. *
  17. * {@inheritdoc}
  18. */
  19. public function validate(array $data)
  20. {
  21. $errorMessage = ['Scopes data should have at least one not admin website, group and store.'];
  22. //list of scope names and their identifier for admin scopes in $data.
  23. $entities = [
  24. ScopeInterface::SCOPE_GROUPS => 0,
  25. ScopeInterface::SCOPE_STORES => 'admin',
  26. ScopeInterface::SCOPE_WEBSITES => 'admin'
  27. ];
  28. foreach ($entities as $scopeName => $key) {
  29. if (empty($data[$scopeName])
  30. || (count($data[$scopeName]) == 1 && isset($data[$scopeName][$key]))) {
  31. return $errorMessage;
  32. }
  33. }
  34. return [];
  35. }
  36. }