Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PatchReader.php
Go to the documentation of this file.
1 <?php
8 
13 
18 {
22  const SETUP_PATCH_FOLDER = 'Patch';
23 
27  private $componentRegistrar;
28 
32  private $type;
33 
38  public function __construct(
39  ComponentRegistrar $componentRegistrar,
40  $type
41  ) {
42  $this->componentRegistrar = $componentRegistrar;
43  $this->type = $type;
44  }
45 
52  private function getPatchFolder($modulePath)
53  {
54  return $modulePath . DIRECTORY_SEPARATOR . Dir::MODULE_SETUP_DIR .
55  DIRECTORY_SEPARATOR . self::SETUP_PATCH_FOLDER;
56  }
57 
64  private function getModuleNameForNamespace($moduleName)
65  {
66  return str_replace('_', '\\', $moduleName);
67  }
68 
74  private function getTypeFolder()
75  {
76  return ucfirst($this->type);
77  }
78 
86  private function getPatchClassesPerModule($moduleName, $modulePath)
87  {
88  $patchClasses = [];
89  $patchesPath = $this->getPatchFolder($modulePath);
90  $specificPatchPath = $patchesPath . DIRECTORY_SEPARATOR . $this->getTypeFolder();
91  $patchesMask = $specificPatchPath . DIRECTORY_SEPARATOR . '*.php';
92 
93  foreach (Glob::glob($patchesMask) as $patchPath) {
94  $moduleName = $this->getModuleNameForNamespace($moduleName);
95  $patchClasses[] = $moduleName . '\\Setup\\' .
96  self::SETUP_PATCH_FOLDER . '\\' .
97  $this->getTypeFolder() . '\\' .
98  basename($patchPath, '.php');
99  }
100 
101  return $patchClasses;
102  }
103 
108  public function read($moduleName)
109  {
110  $modulePath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
111  $patches = $this->getPatchClassesPerModule($moduleName, $modulePath);
112  return $patches;
113  }
114 }
__construct(ComponentRegistrar $componentRegistrar, $type)
Definition: PatchReader.php:38
$componentRegistrar
Definition: bootstrap.php:23
static glob($pattern, $flags=0, $forceFallback=false)
Definition: Glob.php:24