Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryModuleDeployment.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Composer\Package\Package;
11 use Composer\IO\IOInterface;
12 
14 {
15  private $configurator;
16  private $io;
17 
18  public function __construct
19  (
20  InventoryConfiguratorInterface $configurator,
21  IOInterface $io
22  ) {
23  $this->configurator = $configurator;
24  $this->io = $io;
25  }
26 
27  public function deploy(Package $package): void
28  {
29  if ($package->getType() !== 'magento2-module') {
30  return;
31  }
32 
33  $packageName = $package->getName();
34  if (0 !== strpos($packageName,'magento/module-inventory')) {
35  return;
36  }
37 
38  $moduleName = $this->packageNameToModuleName($packageName);
39  $this->io->writeError(sprintf(
40  ' ...Module %s recognized as part of Magento Multi Source Inventory implementation',
41  $moduleName
42  ), true);
43 
44  $this->configurator->configure($moduleName);
45  }
46 
47  private function packageNameToModuleName(string $packageName): string
48  {
49  $nameWithDashes = substr($packageName, strlen('magento/module-'));
50  $nameInCamelCase = ucwords($nameWithDashes, '-');
51  $nameWithoutDashes = str_replace('-', '', $nameInCamelCase);
52  $nameWithVendorPrefix = 'Magento_' . $nameWithoutDashes;
53  $packageName = $nameWithVendorPrefix;
54  return $packageName;
55  }
56 }
__construct(InventoryConfiguratorInterface $configurator, IOInterface $io)