VersionInfo.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * This file is part of the Klarna Core module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Core\Helper;
  11. use Magento\Framework\App\ProductMetadataInterface;
  12. use Magento\Framework\App\State;
  13. use Magento\Framework\Module\ResourceInterface;
  14. /**
  15. * Class VersionInfo
  16. *
  17. * @package Klarna\Core\Helper
  18. */
  19. class VersionInfo
  20. {
  21. /**
  22. * @var State
  23. */
  24. private $appState;
  25. /**
  26. * @var ResourceInterface
  27. */
  28. private $resource;
  29. /**
  30. * ProductMetadataInterface
  31. */
  32. private $productMetadata;
  33. /**
  34. * VersionInfo constructor.
  35. *
  36. * @param ProductMetadataInterface $productMetadata
  37. * @param State $appState
  38. * @param ResourceInterface $resource
  39. */
  40. public function __construct(
  41. ProductMetadataInterface $productMetadata,
  42. State $appState,
  43. ResourceInterface $resource
  44. ) {
  45. $this->appState = $appState;
  46. $this->productMetadata = $productMetadata;
  47. $this->resource = $resource;
  48. }
  49. /**
  50. * Get module version info
  51. *
  52. * @param string $packageName
  53. * @return array|bool
  54. */
  55. public function getVersion($packageName)
  56. {
  57. return $this->resource->getDataVersion($packageName);
  58. }
  59. /**
  60. * Gets the current MAGE_MODE setting
  61. *
  62. * @return string
  63. */
  64. public function getMageMode()
  65. {
  66. return $this->appState->getMode();
  67. }
  68. /**
  69. * Gets the current Magento version
  70. *
  71. * @return string
  72. */
  73. public function getMageVersion()
  74. {
  75. return $this->productMetadata->getVersion();
  76. }
  77. /**
  78. * Gets the current Magento Edition
  79. *
  80. * @return string
  81. */
  82. public function getMageEdition()
  83. {
  84. return $this->productMetadata->getEdition();
  85. }
  86. }