EnabledConnection.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Publisher\Config\Validator;
  7. use Magento\Framework\MessageQueue\Publisher\Config\ValidatorInterface;
  8. /**
  9. * Publisher config data validator. Validates that publisher has only one enabled connection at the same time
  10. */
  11. class EnabledConnection implements ValidatorInterface
  12. {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function validate($configData)
  17. {
  18. $errors = [];
  19. foreach ($configData as $name => $publisherData) {
  20. if (!isset($publisherData['connections'])) {
  21. continue;
  22. }
  23. $enabledConnections = 0;
  24. foreach ($publisherData['connections'] as $connectionConfig) {
  25. if ($connectionConfig['disabled'] == false) {
  26. $enabledConnections++;
  27. }
  28. }
  29. if ($enabledConnections > 1) {
  30. $errors[] = sprintf('More than 1 enabled connections configured for publisher %s.', $name);
  31. }
  32. }
  33. if (!empty($errors)) {
  34. throw new \LogicException(implode(' ', $errors));
  35. }
  36. }
  37. }