MigrationFactory.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Module\Setup;
  7. /**
  8. * Factory class for \Magento\Framework\Module\Setup\Migration
  9. */
  10. class MigrationFactory
  11. {
  12. /**
  13. * Object Manager instance
  14. *
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. protected $_objectManager = null;
  18. /**
  19. * Instance name to create
  20. *
  21. * @var string
  22. */
  23. protected $_instanceName = null;
  24. /**
  25. * Factory constructor
  26. *
  27. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  28. * @param string $instanceName
  29. */
  30. public function __construct(
  31. \Magento\Framework\ObjectManagerInterface $objectManager,
  32. $instanceName = \Magento\Framework\Module\Setup\Migration::class
  33. ) {
  34. $this->_objectManager = $objectManager;
  35. $this->_instanceName = $instanceName;
  36. }
  37. /**
  38. * Create class instance with specified parameters
  39. *
  40. * @param array $data
  41. * @return \Magento\Framework\Module\Setup\Migration
  42. * @throws \InvalidArgumentException
  43. */
  44. public function create(array $data = [])
  45. {
  46. $migrationInstance = $this->_objectManager->create($this->_instanceName, $data);
  47. if (!$migrationInstance instanceof \Magento\Framework\Module\Setup\Migration) {
  48. throw new \InvalidArgumentException(
  49. $this->_instanceName . ' doesn\'n extend \Magento\Framework\Module\Setup\Migration'
  50. );
  51. }
  52. return $migrationInstance;
  53. }
  54. }