%PDF- %PDF-moduleManager = $moduleManager; $this->moduleReader = $moduleReader; $this->filesystem = $filesystem; $this->json = $json; } /** * @return bool */ public function isCoreModuleEnabled() { return $this->moduleManager->isEnabled(self::BSS_CORE_MODULE_NAME); } /** * @return array|mixed|string */ public function getModuleName() { $localModule = $this->getLocalModuleInfo(); if (empty($localModule)) { return ''; } $suite = null; if (isset($localModule['extra']['suite'])) { $suite = $localModule['extra']['suite']; } if ($this->moduleManager->isEnabled('Bss_Breadcrumbs') && $suite == 'seo-suite') { return ''; } $packageName = $localModule['description']; $apiName = $localModule['name']; $remoteModuleInfo = $this->getBssModuleInfo($apiName); if (!empty($remoteModuleInfo) && isset($remoteModuleInfo['data']['module']['product_name'])) $moduleName = $remoteModuleInfo['data']['module']['product_name']; if (empty($moduleName)) $moduleName = $packageName; return $moduleName; } /** * Get installed module info by composer.json. * * @return array|bool|float|int|mixed|string|null */ public function getLocalModuleInfo() { try { $dir = $this->moduleReader->getModuleDir('', $this->_getModuleName()); $file = $dir . '/composer.json'; $string = $this->filesystem->fileGetContents($file); $result = $this->json->unserialize($string); if (!is_array($result) || !array_key_exists('version', $result) || !array_key_exists('description', $result) ) { return ''; } return $result; } catch (\Exception $e) { return []; } } /** * @param string $apiName * @return array */ protected function getBssModuleInfo(string $apiName): array { $headers = ['Content-Type: application/json']; $query = " query { module (api_name: \"$apiName\") { product_name product_url } }"; try { if (false === $data = file_get_contents(self::BSS_GRAPHQL_ENDPOINT, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => $headers, 'content' => $this->json->serialize(['query' => $query]), ] ]))) { $error = error_get_last(); throw new \ErrorException($error['message'], $error['type']); } return $this->json->unserialize($data); } catch (\ErrorException $exception) { $this->_logger->critical($exception->getMessage()); return []; } catch (\Exception $exception) { $this->_logger->critical($exception->getMessage()); return []; } } }