Locales.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Util\Command;
  7. use Magento\Mtf\Util\Protocol\CurlInterface;
  8. use Magento\Mtf\Util\Protocol\CurlTransport;
  9. /**
  10. * Returns array of locales depends on fetching type.
  11. */
  12. class Locales
  13. {
  14. /**
  15. * Type key for fetching all configuration locales.
  16. */
  17. const TYPE_ALL = 'all';
  18. /**
  19. * Type key for fetching locales that have deployed static content.
  20. */
  21. const TYPE_DEPLOYED = 'deployed';
  22. /**
  23. * Url to locales.php.
  24. */
  25. const URL = 'dev/tests/functional/utils/locales.php';
  26. /**
  27. * Curl transport protocol.
  28. *
  29. * @var CurlTransport
  30. */
  31. private $transport;
  32. /**
  33. * @param CurlTransport $transport Curl transport protocol
  34. */
  35. public function __construct(CurlTransport $transport)
  36. {
  37. $this->transport = $transport;
  38. }
  39. /**
  40. * Returns array of locales depends on fetching type.
  41. *
  42. * @param string $type locales fetching type
  43. * @return array of locale codes, for example: ['en_US', 'fr_FR']
  44. */
  45. public function getList($type = self::TYPE_ALL)
  46. {
  47. $url = $_ENV['app_frontend_url'] . self::URL . '?type=' . $type;
  48. $curl = $this->transport;
  49. $curl->write($url, [], CurlInterface::GET);
  50. $result = $curl->read();
  51. $curl->close();
  52. return explode('|', $result);
  53. }
  54. }