/** * @param string $dataString * * @return void */ private function writeDataStringToFile($dataString) { $historyFilePath = $this->globalComputedConfig->getHistoryFile(); if (!$this->globalFunction->file_exists($historyFilePath)) { $this->fileUtil->createDirectoriesWhenNeededForFile($historyFilePath); } $this->globalFunction->file_put_contents($historyFilePath, $dataString); }
/** * Insert $text into file at the last occurrence of the marker. * if $file doesnt exist then $file is created and $text added to $file * * @param string $file * @param string $marker * @param string $text * * @return void */ private function insertIntoFile($file, $marker, $text) { if (!file_exists($file)) { $this->fileUtil->putContent($file, $text); } else { // Pull the file contents, get the last occurrence of $marker. $contents = file_get_contents($file); $pos = strrpos($contents, $marker); // add before the last occurrence of marker our $text. // To achieve this we replace $marker with $text and append $marker again $new_contents = substr_replace($contents, "\n" . $text . "\n" . $marker . "\n", $pos, strlen($text) + strlen($contents)); $this->fileUtil->putContent($file, $new_contents); } }
/** * @param \Box\TestScribe\Spec\SpecsPerClass $spec * * @param string $specFilePath * * @return void */ public function writeSpec(SpecsPerClass $spec, $specFilePath) { $specsArray = $this->specsPerClassPersistence->encodeSpecsPerClass($spec); $specAsYamlString = $this->yamlUtil->dumpToString($specsArray); $this->fileUtil->putContent($specFilePath, $specAsYamlString); }