PatchFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup\Patch;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * This factory allows to create data patches:
  10. * @see PatchInterface
  11. */
  12. class PatchFactory
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @param ObjectManagerInterface $objectManager
  20. */
  21. public function __construct(ObjectManagerInterface $objectManager)
  22. {
  23. $this->objectManager = $objectManager;
  24. }
  25. /**
  26. * Create new instance of patch
  27. *
  28. * @param string $instanceName
  29. * @param array $arguments
  30. * @return PatchInterface
  31. */
  32. public function create($instanceName, $arguments = [])
  33. {
  34. $patchInstance = $this->objectManager->create('\\' . $instanceName, $arguments);
  35. if (!$patchInstance instanceof PatchInterface) {
  36. throw new \InvalidArgumentException(
  37. sprintf(
  38. "%s should implement %s interface",
  39. $instanceName,
  40. PatchInterface::class
  41. )
  42. );
  43. }
  44. return $patchInstance;
  45. }
  46. }