ValidatorFactory.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Model\DeploymentConfig;
  7. use Magento\Framework\App\DeploymentConfig\ValidatorInterface;
  8. use Magento\Framework\ObjectManagerInterface;
  9. /**
  10. * Factory for validators.
  11. *
  12. * Creates object instance that implements Magento\Framework\App\DeploymentConfig\ValidatorInterface interface.
  13. */
  14. class ValidatorFactory
  15. {
  16. /**
  17. * Magento object manager.
  18. *
  19. * @var ObjectManagerInterface
  20. */
  21. private $objectManager;
  22. /**
  23. * @param ObjectManagerInterface $objectManager the magento object manager
  24. */
  25. public function __construct(ObjectManagerInterface $objectManager)
  26. {
  27. $this->objectManager = $objectManager;
  28. }
  29. /**
  30. * Creates object instance by class name.
  31. *
  32. * @param string $className the name of class for creation of its object instance
  33. * @param array $data the array with some additional configuration data for creation of object instance
  34. * @return ValidatorInterface the created object instance
  35. * @throws \InvalidArgumentException is thrown when object instance does not implement ValidatorInterface
  36. */
  37. public function create($className, array $data = [])
  38. {
  39. $importer = $this->objectManager->create($className, $data);
  40. if (!$importer instanceof ValidatorInterface) {
  41. throw new \InvalidArgumentException(
  42. 'Type "' . $className . '" is not instance of ' . ValidatorInterface::class
  43. );
  44. }
  45. return $importer;
  46. }
  47. }