<?php
namespace wcf\system\template;
-use wcf\system\io\File;
+use wcf\system\io\AtomicWriter;
/**
* Compiles template source into valid PHP code.
* @param array $metaData
*/
public function compile($templateName, $sourceContent, $compiledFilename, $metaData) {
+ $writer = new AtomicWriter($compiledFilename);
// build fileheader for template
- $compiledHeader = "<?php\n/**\n * WoltLab Community Framework\n * Template: ".$templateName."\n * Compiled at: ".gmdate('r')."\n * \n * DO NOT EDIT THIS FILE\n */\n\$this->v['tpl']['template'] = '".addcslashes($templateName, "'\\")."';\n?>\n";
+ $writer->write("<?php\n/**\n * WoltLab Community Framework\n * Template: ".$templateName."\n * Compiled at: ".gmdate('r')."\n * \n * DO NOT EDIT THIS FILE\n */\n\$this->v['tpl']['template'] = '".addcslashes($templateName, "'\\")."';\n?>\n");
// include plug-ins
$compiledContent = $this->compileString($templateName, $sourceContent, $metaData);
-
- // write compiled template to file
- $file = new File($compiledFilename);
- $file->write($compiledHeader.$compiledContent['template']);
- $file->close();
+ $writer->write($compiledContent['template']);
// write meta data to file
$this->saveMetaData($templateName, $metaData['filename'], $compiledContent['meta']);
+
+ $writer->flush();
+ $writer->close();
}
/**
* @param string $content
*/
public function saveMetaData($templateName, $filename, $content) {
- $file = new File($filename);
- $file->write("<?php exit; /* meta data for template: ".$templateName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
- $file->write(serialize($content));
- $file->close();
+ $writer = new AtomicWriter($filename);
+ $writer->write("<?php exit; /* meta data for template: ".$templateName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
+ $writer->write(serialize($content));
+ $writer->flush();
+ $writer->close();
}
/**