CompositeValidator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Topology\Config;
  7. /**
  8. * Topology config data validator.
  9. */
  10. class CompositeValidator implements ValidatorInterface
  11. {
  12. /**
  13. * Config validator list.
  14. *
  15. * @var ValidatorInterface[]
  16. */
  17. private $validators;
  18. /**
  19. * Validator constructor.
  20. *
  21. * @param ValidatorInterface[] $validators
  22. */
  23. public function __construct($validators)
  24. {
  25. $this->validators = $validators;
  26. }
  27. /**
  28. * Validate merged topology config data.
  29. *
  30. * @param array $configData
  31. * @throws \LogicException
  32. * @return void
  33. * @throws \LogicException
  34. */
  35. public function validate($configData)
  36. {
  37. foreach ($this->validators as $validator) {
  38. if (!$validator instanceof ValidatorInterface) {
  39. throw new \LogicException(
  40. sprintf(
  41. 'Validator [%s] does not implements %s',
  42. ValidatorInterface::class,
  43. get_class($validator)
  44. )
  45. );
  46. }
  47. $validator->validate($configData);
  48. }
  49. }
  50. }