Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BasePackageInfo.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Model;
7 
8 use Magento\Framework\FileSystem\Directory\ReadFactory;
9 
15 {
16  const MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE = 'magento/magento2-base/composer.json';
17 
18  const COMPOSER_KEY_EXTRA = 'extra';
19 
20  const COMPOSER_KEY_MAP = 'map';
21 
25  private $reader;
26 
32  public function __construct(ReadFactory $readFactory)
33  {
34  $this->reader = $readFactory->create(BP);
35  }
36 
43  public function getPaths()
44  {
45  // Locate composer.json for magento2-base module
46  $filesPathList = [];
47  $vendorDir = require VENDOR_PATH;
48  $basePackageComposerFilePath = $vendorDir . '/' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE;
49  if (!$this->reader->isExist($basePackageComposerFilePath)) {
50  throw new \Magento\Setup\Exception(
51  'Could not locate ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
52  );
53  }
54  if (!$this->reader->isReadable($basePackageComposerFilePath)) {
55  throw new \Magento\Setup\Exception(
56  'Could not read ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
57  );
58  }
59 
60  // Fill array with list of files and directories from extra/map section
61  $composerJsonFileData = json_decode($this->reader->readFile($basePackageComposerFilePath), true);
62  if (!isset($composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP])) {
63  return $filesPathList;
64  }
65  $extraMappings = $composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP];
66  foreach ($extraMappings as $map) {
67  $filesPathList[] = $map[1];
68  }
69  return $filesPathList;
70  }
71 }
if(!file_exists(VENDOR_PATH)) $vendorDir
Definition: autoload.php:25
__construct(ReadFactory $readFactory)
const VENDOR_PATH
Definition: autoload.php:16
const BP
Definition: autoload.php:14