Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryConfiguratorFactory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Composer\IO\IOInterface;
16 
18 {
22  private $deploymentConfig;
23 
27  private $io;
28 
29  public function __construct(IOInterface $io)
30  {
31  $this->io = $io;
32  }
33 
34  public function createConfigurator(string $projectDir): InventoryConfiguratorInterface
35  {
36  $deploymentConfig = $this->getDeploymentConfig($projectDir);
37  if ($this->isModulesConfigured($deploymentConfig)) {
38  $deploymentConfigWriter = $this->createDeploymentConfigWriter($projectDir);
40  $deploymentConfig,
41  $deploymentConfigWriter,
42  $this->io
43  );
44  } else {
45  return new NoChangesConfigurator($this->io);
46  }
47  }
48 
49  private function isModulesConfigured(DeploymentConfig $deploymentConfig): bool
50  {
51  return is_array($deploymentConfig->get('modules'));
52  }
53 
54  private function getDeploymentConfig(string $projectDir): DeploymentConfig
55  {
56  $cacheKey = realpath($projectDir);
57  if (!isset($this->deploymentConfig[$cacheKey])) {
58  $this->deploymentConfig[$cacheKey] = $this->createDeploymentConfig($projectDir);
59  }
60  return $this->deploymentConfig[$cacheKey];
61  }
62 
63  private function createDeploymentConfig(string $projectDir): DeploymentConfig
64  {
65  $deploymentConfigReader = $this->createDeploymentConfigReader($projectDir);
66  $deploymentConfig = new DeploymentConfig($deploymentConfigReader);
67  return $deploymentConfig;
68  }
69 
70  private function createDeploymentConfigReader(string $projectDir): DeploymentConfig\Reader
71  {
72  $dirList = $this->createDirectoryList($projectDir);
73  $filesystemDriverPool = $this->createFilesystemDriverPool();
74  $configFilePool = $this->createConfigFilePool();
75  $reader = new DeploymentConfig\Reader(
76  $dirList,
77  $filesystemDriverPool,
78  $configFilePool
79  );
80  return $reader;
81  }
82 
83  private function createDeploymentConfigWriter(string $projectDir): DeploymentConfig\Writer
84  {
85  $deploymentConfigReader = $this->createDeploymentConfigReader($projectDir);
86  $configFilePool = $this->createConfigFilePool();
87  $deploymentConfig = $this->createDeploymentConfig($projectDir);
88  $dirList = $this->createDirectoryList($projectDir);
89  $filesystemDriverPool = $this->createFilesystemDriverPool();
90  $filesystemReader = new Filesystem\Directory\ReadFactory($filesystemDriverPool);
91  $filesystemWriter = new Filesystem\Directory\WriteFactory($filesystemDriverPool);
92  $filesystem = new Filesystem(
93  $dirList,
94  $filesystemReader,
95  $filesystemWriter
96  );
97 
98  $deploymentConfigWriter = new DeploymentConfig\Writer(
99  $deploymentConfigReader,
100  $filesystem,
101  $configFilePool,
102  $deploymentConfig
103  );
104  return $deploymentConfigWriter;
105  }
106 
107  private function createDirectoryList(string $projectDir): DirectoryList
108  {
109  $dirsConfig = DirectoryList::getDefaultConfig();
110  $dirsConfig[DirectoryList::ROOT] = $projectDir;
111  $dirList = new DirectoryList($projectDir, $dirsConfig);
112  return $dirList;
113  }
114 
115  private function createFilesystemDriverPool(): DriverPool
116  {
117  $driverPool = new DriverPool();
118  return $driverPool;
119  }
120 
121  private function createConfigFilePool(): ConfigFilePool
122  {
123  $configFilePool = new ConfigFilePool();
124  return $configFilePool;
125  }
126 }
if(!file_exists($installConfigFile)) $dirList
Definition: bootstrap.php:57
$deploymentConfig
$filesystem