DeployStrategyFactory.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Strategy;
  7. use Magento\Framework\Exception\InputException;
  8. use Magento\Framework\ObjectManagerInterface;
  9. /**
  10. * Abstract factory class for instances of @see \Magento\Deploy\Strategy\StrategyInterface
  11. */
  12. class DeployStrategyFactory
  13. {
  14. /**
  15. * Standard deploy strategy
  16. */
  17. const DEPLOY_STRATEGY_STANDARD = 'standard';
  18. /**
  19. * Quick deploy strategy
  20. */
  21. const DEPLOY_STRATEGY_QUICK = 'quick';
  22. /**
  23. * Standard deploy strategy
  24. */
  25. const DEPLOY_STRATEGY_COMPACT = 'compact';
  26. /**
  27. * @var ObjectManagerInterface
  28. */
  29. private $objectManager;
  30. /**
  31. * Deployment strategies
  32. *
  33. * @var array
  34. */
  35. private $strategies = [];
  36. /**
  37. * DeployStrategyFactory constructor
  38. *
  39. * @param ObjectManagerInterface $objectManager
  40. * @param array $strategies
  41. */
  42. public function __construct(ObjectManagerInterface $objectManager, array $strategies = [])
  43. {
  44. $this->objectManager = $objectManager;
  45. $defaultStrategies = [
  46. self::DEPLOY_STRATEGY_STANDARD => StandardDeploy::class,
  47. self::DEPLOY_STRATEGY_QUICK => QuickDeploy::class,
  48. self::DEPLOY_STRATEGY_COMPACT => CompactDeploy::class,
  49. ];
  50. $this->strategies = array_replace($defaultStrategies, $strategies);
  51. }
  52. /**
  53. * Create new instance of deployment strategy
  54. *
  55. * @param string $type
  56. * @param array $arguments
  57. * @return StrategyInterface
  58. * @throws InputException
  59. */
  60. public function create($type, array $arguments = [])
  61. {
  62. $type = $type ?: self::DEPLOY_STRATEGY_STANDARD;
  63. if (!isset($this->strategies[$type])) {
  64. throw new InputException(__('Wrong deploy strategy type: %1', $type));
  65. }
  66. return $this->objectManager->create($this->strategies[$type], $arguments);
  67. }
  68. }