/** * @param string $fileName * @param string $content * @throws FileSystemException * @return bool */ public function writeResultFile($fileName, $content) { /** * Rename is atomic on *nix systems, while file_put_contents is not. Writing to a * temporary file whose name is process-unique and renaming to the real location helps * avoid race conditions. Race condition can occur if the compiler has not been run, when * multiple processes are attempting to access the generated file simultaneously. */ $content = "<?php\n" . $content; $tmpFile = $fileName . "." . getmypid(); $this->filesystemDriver->filePutContents($tmpFile, $content); try { $success = $this->filesystemDriver->rename($tmpFile, $fileName); } catch (FileSystemException $e) { if (!$this->fileExists($fileName)) { throw $e; } else { /** * Due to race conditions, file may have already been written, causing rename to fail. As long as * the file exists, everything is okay. */ $success = true; } } return $success; }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir, \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * {@inheritdoc} */ public function handle(array $record) { if (!$this->isHandling($record)) { return false; } $logFile = $this->config->getOption('log_file'); $record['formatted'] = $this->getFormatter()->format($record); if ($logFile) { $filePath = $this->getFilePath($logFile); $this->file->filePutContents($filePath, $record['formatted'] . PHP_EOL, FILE_APPEND); } return false === $this->bubble; }
/** * @param string $fileName * @param string $content * @return bool */ public function writeResultFile($fileName, $content) { $content = "<?php\n" . $content; return $this->filesystemDriver->filePutContents($fileName, $content); }