本文整理汇总了PHP中FileWriter类的典型用法代码示例。如果您正苦于以下问题:PHP FileWriter类的具体用法?PHP FileWriter怎么用?PHP FileWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resetCrontab
public static function resetCrontab()
{
$cron_file = 'cron.txt';
$cron = new FileWriter($cron_file, 'a');
$setSessionPath = '/home1/enderrac/SpirePHP/setSessionWinner.php';
$stm = "SELECT EXTRACT(MINUTE from end_ts) as minute, " . "\tEXTRACT(HOUR from end_ts) as hour, " . "\tEXTRACT(day from end_ts) as day_of_month, " . "\tEXTRACT(MONTH from end_ts) as month, " . "\tEXTRACT(dow from end_ts) as day_of_week, " . "\tid " . "FROM SPIRE.SESSIONS ";
$result = ConnDB::query_db($stm);
$fnHash = null;
if (!$result) {
$cron->writeLine("ERROR");
$fnHash = MyUtil::fnOk(false, "SQL Error getting Session Info", null);
} else {
while ($row = pg_fetch_assoc($result)) {
$cron->writeLine($row['minute'] . " " . $row['hour'] . " " . $row['day_of_month'] . " " . $row['month'] . " " . $row['day_of_week'] . " {$setSessionPath} " . $row['id']);
}
$rmCron = shell_exec('crontab -r');
if ($rmCron != null) {
$setCron = shell_exec('crontab $cron_file');
if ($setCron != null) {
$delCronTmp = shell_exec('rm $cron_file');
if ($delCronTmp != null) {
$fnHash = MyUtil::fnOk(true, "Updated Cron and Session", null);
}
$fnHash = MyUtil::fnOk(false, "Cron Tmp File not Deleted", null);
}
$fnHash = MyUtil::fnOk(false, "Cron not set to tmp", null);
} else {
$fnHash = MyUtil::fnOk(false, "Original cron not deleted", null);
}
return $fnHash;
}
return $fnHash;
}
示例2: getWinningVideoId
public static function getWinningVideoId($id)
{
$logger = new FileWriter('win_id_log', 'a');
if (!is_integer($id) || $id <= 0) {
$fnOk = MyUtil::fnOk(false, "Invalid Session ID: {$id}" . !is_integer($id) . "-" . ($id <= 0), null);
$logger->writeLog($fnOk['reason']);
return $fnOk;
}
$stm = "SELECT COALESCE(winner_video_id, 0) as winner_video_id FROM " . self::$table_name . " WHERE id = {$id}";
$logger->writeLog($stm);
$result = ConnDB::query_db($stm);
if (!$result) {
return MyUtil::fnOk(false, "SQL Error", null);
}
$row = pg_fetch_assoc($result);
if ($row['winner_video_id'] > 0) {
return MyUtil::fnOk(true, "Video Id Found", $row['winner_video_id']);
} else {
$stm = " SELECT COALESCE(id, 0) as winner_video_id " . " FROM spire.videos " . " WHERE session_id = {$id} " . " AND votes = (SELECT MAX(votes) FROM spire.videos WHERE session_id = {$id})";
$logger->writeLog($stm);
$result = ConnDB::query_db($stm);
if (!$result) {
return MyUtil::fnOk(false, "SQL Error", null);
}
$row = pg_fetch_assoc($result);
if ($row['winner_video_id'] > 0) {
return MyUtil::fnOk(true, "Video Id Found", $row['winner_video_id']);
} else {
return MyUtil::fnOk(false, "Video Id Not Found", null);
}
}
}
示例3: testWriter
public function testWriter()
{
$filename = tempnam(sys_get_temp_dir(), 'phpwriter');
$writer = new FileWriter($filename);
$writer->write('some text');
$writer->close();
$this->assertEquals('some text', file_get_contents($filename));
// clean up temp file
unlink($filename);
}
示例4: connect
/**
* Returns routes to connect to the given application.
*
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->get('{_locale}', function ($_locale) use($app) {
$directoryTrans = __DIR__ . '/../../../../../../app/trans/en.json';
$oldCatalogue = new DataCatalogue();
$oldCatalogue->load($directoryTrans, 'json', 'en');
$extractor = new FileExtractor($this->twig);
$catalogue = $extractor->extract();
$fileWriter = new FileWriter();
$fileWriter->write($catalogue, $directoryTrans, 'json');
return $app['twig']->render('Demo/Default/test.html.twig');
})->bind('blueLinesHome');
return $controllers;
}
示例5: save
public static function save(Utility $utility)
{
$file = UTILITIES . "/{$utility->name}";
FileWriter::write($file, $utility->body, Symphony::Configuration()->core()->symphony->{'file-write-mode'});
//General::writeFile($file, $utility->body,Symphony::Configuration()->core()->symphony->{'file-write-mode'});
return file_exists($file);
}
示例6: mergeBehaviorChangesIfIncludeEmptyValuesIsFalse
/**
*
* @test
*/
public function mergeBehaviorChangesIfIncludeEmptyValuesIsFalse()
{
$testString1 = 'extConf';
// install tool is empty in local configuration, leave remote setting intact...
$testString2 = "'installToolPassword' => '2ccbdfbea4716a57da75f4c8e8d651ac',";
$this->fileWriter->expects($this->once())->method('write')->with($this->logicalAnd($this->stringContains($testString1), $this->stringContains($testString2)));
$this->task->setBase($this->base);
$this->task->setUpdate($this->update);
$this->task->setIncludeEmptyValues(FALSE);
$this->task->addFileWriter($this->fileWriter);
$this->task->main();
}
示例7: CreateSongFile
private function CreateSongFile($title, $artist, $viewModel)
{
if (strlen($title) < 1) {
$viewModel->HasErrors = true;
$viewModel->Message = 'Song title is required, sorry.';
return false;
}
try {
$fWriter = new FileWriter();
$viewModel->Id = $fWriter->MakeFile($title, $artist);
$viewModel->HasErrors = strlen($viewModel->Id) < 1;
if ($viewModel->HasErrors) {
$viewModel->Message = '(e:803) Something\'s gone wrong whilst saving.';
return false;
}
} catch (Exception $e) {
$viewModel->Message = '(e:805) Something\'s gone wrong whilst saving.';
return false;
}
$viewModel->ContinueUri = Ugs::MakeUri(Actions::Edit, $viewModel->Id);
return true;
}
示例8: transform
private function transform(DOMDocument $document)
{
$dir = new PhingFile($this->toDir);
if (!$dir->exists()) {
throw new BuildException("Directory '" . $this->toDir . "' does not exist");
}
$xslfile = $this->getStyleSheet();
$xsl = new DOMDocument();
$xsl->load($xslfile->getAbsolutePath());
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
if ($this->format == "noframes") {
$writer = new FileWriter(new PhingFile($this->toDir, "checkstyle-noframes.html"));
$writer->write($proc->transformToXML($document));
$writer->close();
} else {
ExtendedFileStream::registerStream();
// no output for the framed report
// it's all done by extension...
$dir = new PhingFile($this->toDir);
$proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
$proc->transformToXML($document);
}
}
示例9: export_table_csv_utf8
/**
* Export tabular data to CSV-file
* @param array $data
* @param string $filename
*/
public static function export_table_csv_utf8($data, $filename = 'export')
{
if (empty($data)) {
return false;
}
$path = Chamilo::temp_file();
$converter = new Utf8Encoder(null, true);
$file = FileWriter::create($path, $converter);
$file = CsvWriter::create($file);
foreach ($data as $row) {
$file->put($row);
}
$file->close();
DocumentManager::file_send_for_download($path, false, $filename . '.csv');
unlink($path);
exit;
}
示例10: main
public function main()
{
if (NULL === $this->base) {
throw new BuildException('You must specify the base file!');
}
if (NULL === $this->update) {
throw new BuildException('You must specify the update file!');
}
$baseConfiguration = (array) (include $this->base->getAbsolutePath());
$updateConfiguration = (array) (include $this->update->getAbsolutePath());
$mergedConfiguration = ArrayUtility::array_merge_recursive_overrule($baseConfiguration, $updateConfiguration, FALSE, $this->includeEmptyValues);
$configuration = new ConfigurationUtility($mergedConfiguration);
$phpCode = $configuration->getLocalConfigurationArray();
if (NULL === $this->fileWriter) {
$this->addFileWriter();
}
$this->fileWriter->write($phpCode);
$this->fileWriter->close();
}
示例11: ServletContext
function ServletContext($web_xml_file)
{
$web_xml_file = new File($web_xml_file);
if (File::validClass($web_xml_file) && $web_xml_file->exists()) {
$this->file =& $web_xml_file;
$cache_file = new File($web_xml_file->getFilePath() . 'cached');
$valid_cache = FALSE;
if ($cache_file->exists() && $web_xml_file->lastModified() == $cache_file->lastModified()) {
$this->config = @unserialize(FileReader::readFileContent($cache_file));
if (ServletContext::validClass($this->config)) {
$valid_cache = TRUE;
}
}
if (!$valid_cache) {
$this->config =& ServletXMLConfigReader::readXMLConfig(new FileReader($web_xml_file));
FileWriter::writeToFile($cache_file, serialize($this->config), $web_xml_file->lastModified());
}
}
if (isset($this->config)) {
$this->initServletContext();
}
}
示例12: store
/**
* Stores current properties to specified file.
*
* @param PhingFile $file File to create/overwrite with properties.
* @param string $header Header text that will be placed (within comments) at the top of properties file.
* @return void
* @throws IOException - on error writing properties file.
*/
function store(PhingFile $file = null, $header = null)
{
if ($file == null) {
$file = $this->file;
}
if ($file == null) {
throw new IOException("Unable to write to empty filename");
}
// stores the properties in this object in the file denoted
// if file is not given and the properties were loaded from a
// file prior, this method stores them in the file used by load()
try {
$fw = new FileWriter($file);
if ($header !== null) {
$fw->write("# " . $header . PHP_EOL);
}
$fw->write($this->toString());
$fw->close();
} catch (IOException $e) {
throw new IOException("Error writing property file: " . $e->getMessage());
}
}
示例13: main
/**
* Execute the input script with Velocity
*
* @throws BuildException
* BuildExceptions are thrown when required attributes are missing.
* Exceptions thrown by Velocity are rethrown as BuildExceptions.
*/
public function main()
{
// Make sure the template path is set.
if (empty($this->templatePath)) {
throw new BuildException("The template path needs to be defined!");
}
// Make sure the control template is set.
if ($this->controlTemplate === null) {
throw new BuildException("The control template needs to be defined!");
}
// Make sure the output directory is set.
if ($this->outputDirectory === null) {
throw new BuildException("The output directory needs to be defined!");
}
// Make sure there is an output file.
if ($this->outputFile === null) {
throw new BuildException("The output file needs to be defined!");
}
// Setup Smarty runtime.
// Smarty uses one object to store properties and to store
// the context for the template (unlike Velocity). We setup this object, calling it
// $this->context, and then initControlContext simply zeros out
// any assigned variables.
//
// Use the smarty backwards compatibility layer if existent.
if (class_exists('SmartyBC')) {
$this->context = new SmartyBC();
} else {
$this->context = new Smarty();
}
if ($this->compilePath !== null) {
$this->log("Using compilePath: " . $this->compilePath);
$this->context->compile_dir = $this->compilePath;
}
if ($this->configPath !== null) {
$this->log("Using configPath: " . $this->configPath);
$this->context->config_dir = $this->configPath;
}
if ($this->forceCompile !== null) {
$this->context->force_compile = $this->forceCompile;
}
if ($this->leftDelimiter !== null) {
$this->context->left_delimiter = $this->leftDelimiter;
}
if ($this->rightDelimiter !== null) {
$this->context->right_delimiter = $this->rightDelimiter;
}
if ($this->templatePath !== null) {
$this->log("Using templatePath: " . $this->templatePath);
$this->context->template_dir = $this->templatePath;
}
$smartyCompilePath = new PhingFile($this->context->compile_dir);
if (!$smartyCompilePath->exists()) {
$this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
if (!$smartyCompilePath->mkdirs()) {
throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir);
}
}
// Make sure the output directory exists, if it doesn't
// then create it.
$file = new PhingFile($this->outputDirectory);
if (!$file->exists()) {
$this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
$file->mkdirs();
}
$path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
$this->log("Generating to file " . $path);
$writer = new FileWriter($path);
// The generator and the output path should
// be placed in the init context here and
// not in the generator class itself.
$c = $this->initControlContext();
// Set any variables that need to always
// be loaded
$this->populateInitialContext($c);
// Feed all the options into the initial
// control context so they are available
// in the control/worker templates.
if ($this->contextProperties !== null) {
foreach ($this->contextProperties->keys() as $property) {
$value = $this->contextProperties->getProperty($property);
// Special exception (from Texen)
// for properties ending in file.contents:
// in that case we dump the contents of the file
// as the "value" for the Property.
if (StringHelper::endsWith("file.contents", $property)) {
// pull in contents of file specified
$property = substr($property, 0, strpos($property, "file.contents") - 1);
// reset value, and then
// read in teh contents of the file into that var
$value = "";
$f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
if ($f->exists()) {
//.........这里部分代码省略.........
示例14: create
function create(&$dto)
{
if (!$dto->copyImageDir) {
$dto->copyImageDir = IMAGES_DIR;
}
if ($dto->copyImageDir == THEME_IMAGES_DIR . "thumbnail/") {
$filename = $this->config->getValue("WEBAPP_THEME_DIR");
$pathList = explode("_", $dto->actionName);
if (isset($pathList[1])) {
$filename .= "/" . $pathList[0] . "/images/" . $pathList[1] . "/";
} else {
$filename .= "/" . $pathList[0] . "/images/";
}
} else {
if ($dto->copyImageDir == THEME_IMAGES_DIR . "images/") {
$filename = $this->config->getValue("WEBAPP_THEME_DIR");
$filename .= "/" . $dto->themeName . "/images/";
} else {
if ($dto->templateDir) {
$filename = $this->config->getValue("WEBAPP_MODULE_DIR") . "/" . $dto->moduleName . "/files/images/" . $dto->templateDir . "/";
} else {
$filename = $this->config->getValue("WEBAPP_MODULE_DIR") . "/" . $dto->moduleName . "/files/images/";
}
}
}
return $this->writer->write($filename, $dto->copyImageDir);
}
示例15: output
/**
* $templateを読み込んで$outputFileに書き出す
* 文字エンコーディングには$outputEncodingを使用する
* $varsはテンプレートから $skeleton としてアクセスできる
*
* 基本的に処理は$writerに委譲し、
* 結果を配列の形にまとめる
*
* $templateの指定がない場合、getTemplateFileで自動生成
* $outputEncodingの指定がない場合、SCRIPT_CODEを使用
*
* @param String $outputFile
* @param array $vars
* @param String $outputEncoding [optional]
* @param String $template [optional]
* @return array
*/
function output($outputFile, $vars, $outputEncoding = 'SCRIPT_CODE', $template = "")
{
if ($template == "") {
$template = $this->getTemplateFile();
}
$stat = '';
if (file_exists($outputFile)) {
$stat = 'exists';
} else {
$stat = $this->writer->write($template, $outputFile, $vars, $outputEncoding) ? 'create' : 'fail';
}
return array($outputFile => $stat);
}