fileManager = $fileManager; $this->metadata = $metadata; } /** * Unite files content. * * @param array $paths * @param bool $returnModuleNames If need to return data with module names. * * @return array */ public function unify(array $paths, bool $returnModuleNames = false): array { $data = $this->loadData($paths['corePath']); if (!empty($paths['modulePath'])) { $moduleDir = strstr($paths['modulePath'], '{*}', true); $moduleList = isset($this->metadata) ? $this->metadata->getModuleList() : $this->fileManager->getFileList($moduleDir, false, '', false); foreach ($moduleList as $moduleName) { $moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']); if ($returnModuleNames) { if (!isset($data[$moduleName])) { $data[$moduleName] = []; } $data[$moduleName] = Util::merge( $data[$moduleName], $this->loadData($moduleFilePath) ); continue; } $data = Util::merge( $data, $this->loadData($moduleFilePath) ); } } if (!empty($paths['customPath'])) { $data = Util::merge( $data, $this->loadData($paths['customPath']) ); } return $data; } /** * Load data from a file. * * @param string $filePath * @param array $returns * @return array */ protected function loadData(string $filePath): array { if (!$this->fileManager->isFile($filePath)) { return []; } $content = $this->fileManager->getContents($filePath); return Json::decode($content, true); } }