Config.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Directory\Model\Currency\Import;
  7. /**
  8. * Configured currency import services
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Config
  14. {
  15. /**
  16. * @var array
  17. */
  18. private $_servicesConfig;
  19. /**
  20. * Validate format of services configuration array
  21. *
  22. * @param array $servicesConfig
  23. * @throws \InvalidArgumentException
  24. */
  25. public function __construct(array $servicesConfig)
  26. {
  27. foreach ($servicesConfig as $serviceName => $serviceInfo) {
  28. if (!is_string($serviceName) || empty($serviceName)) {
  29. throw new \InvalidArgumentException('Name for a currency import service has to be specified.');
  30. }
  31. if (empty($serviceInfo['class'])) {
  32. throw new \InvalidArgumentException('Class for a currency import service has to be specified.');
  33. }
  34. if (empty($serviceInfo['label'])) {
  35. throw new \InvalidArgumentException('Label for a currency import service has to be specified.');
  36. }
  37. }
  38. $this->_servicesConfig = $servicesConfig;
  39. }
  40. /**
  41. * Retrieve unique names of all available currency import services
  42. *
  43. * @return array
  44. */
  45. public function getAvailableServices()
  46. {
  47. return array_keys($this->_servicesConfig);
  48. }
  49. /**
  50. * Retrieve name of a class that corresponds to service name
  51. *
  52. * @param string $serviceName
  53. * @return string|null
  54. */
  55. public function getServiceClass($serviceName)
  56. {
  57. if (isset($this->_servicesConfig[$serviceName]['class'])) {
  58. return $this->_servicesConfig[$serviceName]['class'];
  59. }
  60. return null;
  61. }
  62. /**
  63. * Retrieve already translated label that corresponds to service name
  64. *
  65. * @param string $serviceName
  66. * @return \Magento\Framework\Phrase|null
  67. */
  68. public function getServiceLabel($serviceName)
  69. {
  70. if (isset($this->_servicesConfig[$serviceName]['label'])) {
  71. return __($this->_servicesConfig[$serviceName]['label']);
  72. }
  73. return null;
  74. }
  75. }