LockValidatorComposite.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Attribute lock state validator
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Catalog\Model\Attribute;
  9. class LockValidatorComposite implements LockValidatorInterface
  10. {
  11. /**
  12. * @var LockValidatorInterface[]
  13. */
  14. protected $validators = [];
  15. /**
  16. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  17. * @param array $validators
  18. * @throws \InvalidArgumentException
  19. */
  20. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $validators = [])
  21. {
  22. foreach ($validators as $validator) {
  23. if (!is_subclass_of($validator, \Magento\Catalog\Model\Attribute\LockValidatorInterface::class)) {
  24. throw new \InvalidArgumentException($validator . ' does not implements LockValidatorInterface');
  25. }
  26. $this->validators[] = $objectManager->get($validator);
  27. }
  28. }
  29. /**
  30. * Check attribute lock state
  31. *
  32. * @param \Magento\Framework\Model\AbstractModel $object
  33. * @param null $attributeSet
  34. * @throws \Magento\Framework\Exception\LocalizedException
  35. *
  36. * @return void
  37. */
  38. public function validate(\Magento\Framework\Model\AbstractModel $object, $attributeSet = null)
  39. {
  40. foreach ($this->validators as $validator) {
  41. $validator->validate($object, $attributeSet);
  42. }
  43. }
  44. }