EntryPoint.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\EntryPoint;
  7. use Magento\Mtf\ObjectManager;
  8. /**
  9. * Class EntryPoint
  10. * Application entry point, used to bootstrap and run application
  11. *
  12. */
  13. class EntryPoint
  14. {
  15. /**
  16. * @var string
  17. */
  18. protected $_rootDir;
  19. /**
  20. * @var array
  21. */
  22. protected $_parameters;
  23. /**
  24. * Application object manager
  25. *
  26. * @var ObjectManager
  27. */
  28. protected $_locator;
  29. /**
  30. * @param string $rootDir
  31. * @param array $parameters
  32. * @param ObjectManager $objectManager
  33. * @SuppressWarnings(PHPMD.ExitExpression)
  34. */
  35. public function __construct(
  36. $rootDir,
  37. array $parameters = [],
  38. ObjectManager $objectManager = null
  39. ) {
  40. $this->_rootDir = $rootDir;
  41. $this->_parameters = $parameters;
  42. $this->_locator = $objectManager;
  43. }
  44. /**
  45. * Run a Mtf application
  46. *
  47. * @param $applicationName
  48. * @param array $arguments
  49. * @return mixed
  50. * @throws \DomainException
  51. */
  52. public function run($applicationName, array $arguments = [])
  53. {
  54. try {
  55. if (!$this->_locator) {
  56. $locatorFactory = new \Magento\Mtf\ObjectManagerFactory();
  57. $this->_locator = $locatorFactory->create();
  58. }
  59. return $this->_locator->create($applicationName, $arguments)->launch();
  60. } catch (\Exception $exception) {
  61. $message = "Error happened during application run.\n";
  62. $message .= $exception->getMessage();
  63. throw new \DomainException($message);
  64. }
  65. }
  66. }