deploymentConfig = $deploymentConfig; $this->directoryList = $directoryList; $this->fileDriver = $fileDriver; $this->config = $config; } /** * @return void * @throws \Magento\Framework\Exception\FileSystemException * @throws \Magento\Framework\Exception\RuntimeException */ public function create(): void { $filePath = $this->getFilePath(); $directoryPath = dirname($filePath); if (! $this->fileDriver->isExists($directoryPath)) { $this->fileDriver->createDirectory($directoryPath); } $jsonData = json_encode( [ 'gpc' => $this->config->isModuleEnabled(), 'version' => '1.0', 'created' => $this->config->getWellKnownLastUpdateDate() ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); $this->fileDriver->filePutContents($filePath, $jsonData); } /** * @return string * @throws \Magento\Framework\Exception\FileSystemException * @throws \Magento\Framework\Exception\RuntimeException */ public function getContent(): string { $filePath = $this->getFilePath(); if (! $this->fileDriver->isExists($filePath)) { throw new LocalizedException( __("The .well-known file was not found.") ); } return $this->fileDriver->fileGetContents($filePath); } /** * @return string * @throws \Magento\Framework\Exception\FileSystemException * @throws \Magento\Framework\Exception\RuntimeException */ private function getFilePath(): string { $rootPath = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB) ? $this->directoryList->getPath(DirectoryListApi::PUB) : $this->directoryList->getRoot(); return $rootPath . DIRECTORY_SEPARATOR . '.well-known' . DIRECTORY_SEPARATOR . self::FILE_NAME; } }