AbstractState.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\App\State;
  7. use Magento\Mtf\ObjectManager;
  8. /**
  9. * Provides abstract implementation for Application State Interface.
  10. */
  11. abstract class AbstractState implements StateInterface
  12. {
  13. /**
  14. * Object Manager.
  15. *
  16. * @var ObjectManager
  17. */
  18. protected $objectManager;
  19. /**
  20. * List of handlers.
  21. *
  22. * @var string[]
  23. */
  24. private $arguments;
  25. /**
  26. * Specifies whether to clean instance under test.
  27. *
  28. * @var bool
  29. */
  30. protected $isCleanInstance = false;
  31. /**
  32. * @param ObjectManager $objectManager
  33. * @param array $arguments
  34. */
  35. public function __construct(
  36. ObjectManager $objectManager,
  37. array $arguments = []
  38. ) {
  39. $this->objectManager = $objectManager;
  40. $this->arguments = $arguments;
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function apply()
  46. {
  47. foreach ($this->arguments as $argument) {
  48. $handler = $this->objectManager->get($argument);
  49. $handler->execute($this);
  50. }
  51. if ($this->isCleanInstance) {
  52. $this->clearInstance();
  53. }
  54. }
  55. /**
  56. * @inheritdoc
  57. */
  58. public function clearInstance()
  59. {
  60. //
  61. }
  62. }