Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductMetadata.php
Go to the documentation of this file.
1 <?php
8 namespace Magento\Framework\App;
9 
11 use \Magento\Framework\Composer\ComposerJsonFinder;
12 use \Magento\Framework\App\Filesystem\DirectoryList;
13 use \Magento\Framework\Composer\ComposerInformation;
14 
20 {
24  const EDITION_NAME = 'Community';
25 
29  const PRODUCT_NAME = 'Magento';
30 
36  protected $version;
37 
43 
47  private $composerInformation;
48 
53  {
54  $this->composerJsonFinder = $composerJsonFinder;
55  }
56 
62  public function getVersion()
63  {
64  if (!$this->version) {
65  if (!($this->version = $this->getSystemPackageVersion())) {
66  if ($this->getComposerInformation()->isMagentoRoot()) {
67  $this->version = $this->getComposerInformation()->getRootPackage()->getPrettyVersion();
68  } else {
69  $this->version = 'UNKNOWN';
70  }
71  }
72  }
73  return $this->version;
74  }
75 
81  public function getEdition()
82  {
83  return self::EDITION_NAME;
84  }
85 
91  public function getName()
92  {
93  return self::PRODUCT_NAME;
94  }
95 
102  private function getSystemPackageVersion()
103  {
104  $packages = $this->getComposerInformation()->getSystemPackages();
105  foreach ($packages as $package) {
106  if (isset($package['name']) && isset($package['version'])) {
107  return $package['version'];
108  }
109  }
110  return '';
111  }
112 
119  private function getComposerInformation()
120  {
121  if (!$this->composerInformation) {
122  $directoryList = new DirectoryList(BP);
123  $composerFactory = new ComposerFactory($directoryList, $this->composerJsonFinder);
124  $this->composerInformation = new ComposerInformation($composerFactory);
125  }
126  return $this->composerInformation;
127  }
128 }
__construct(ComposerJsonFinder $composerJsonFinder)
const BP
Definition: autoload.php:14