ProductMetadata.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Magento application product metadata
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App;
  9. use Magento\Framework\Composer\ComposerFactory;
  10. use \Magento\Framework\Composer\ComposerJsonFinder;
  11. use \Magento\Framework\App\Filesystem\DirectoryList;
  12. use \Magento\Framework\Composer\ComposerInformation;
  13. /**
  14. * Class ProductMetadata
  15. * @package Magento\Framework\App
  16. */
  17. class ProductMetadata implements ProductMetadataInterface
  18. {
  19. /**
  20. * Magento product edition
  21. */
  22. const EDITION_NAME = 'Community';
  23. /**
  24. * Magento product name
  25. */
  26. const PRODUCT_NAME = 'Magento';
  27. /**
  28. * Product version
  29. *
  30. * @var string
  31. */
  32. protected $version;
  33. /**
  34. * @var \Magento\Framework\Composer\ComposerJsonFinder
  35. * @deprecated 100.1.0
  36. */
  37. protected $composerJsonFinder;
  38. /**
  39. * @var \Magento\Framework\Composer\ComposerInformation
  40. */
  41. private $composerInformation;
  42. /**
  43. * @param ComposerJsonFinder $composerJsonFinder
  44. */
  45. public function __construct(ComposerJsonFinder $composerJsonFinder)
  46. {
  47. $this->composerJsonFinder = $composerJsonFinder;
  48. }
  49. /**
  50. * Get Product version
  51. *
  52. * @return string
  53. */
  54. public function getVersion()
  55. {
  56. if (!$this->version) {
  57. if (!($this->version = $this->getSystemPackageVersion())) {
  58. if ($this->getComposerInformation()->isMagentoRoot()) {
  59. $this->version = $this->getComposerInformation()->getRootPackage()->getPrettyVersion();
  60. } else {
  61. $this->version = 'UNKNOWN';
  62. }
  63. }
  64. }
  65. return $this->version;
  66. }
  67. /**
  68. * Get Product edition
  69. *
  70. * @return string
  71. */
  72. public function getEdition()
  73. {
  74. return self::EDITION_NAME;
  75. }
  76. /**
  77. * Get Product name
  78. *
  79. * @return string
  80. */
  81. public function getName()
  82. {
  83. return self::PRODUCT_NAME;
  84. }
  85. /**
  86. * Get version from system package
  87. *
  88. * @return string
  89. * @deprecated 100.1.0
  90. */
  91. private function getSystemPackageVersion()
  92. {
  93. $packages = $this->getComposerInformation()->getSystemPackages();
  94. foreach ($packages as $package) {
  95. if (isset($package['name']) && isset($package['version'])) {
  96. return $package['version'];
  97. }
  98. }
  99. return '';
  100. }
  101. /**
  102. * Load composerInformation
  103. *
  104. * @return ComposerInformation
  105. * @deprecated 100.1.0
  106. */
  107. private function getComposerInformation()
  108. {
  109. if (!$this->composerInformation) {
  110. $directoryList = new DirectoryList(BP);
  111. $composerFactory = new ComposerFactory($directoryList, $this->composerJsonFinder);
  112. $this->composerInformation = new ComposerInformation($composerFactory);
  113. }
  114. return $this->composerInformation;
  115. }
  116. }