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; }
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); }
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); } } }
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); }
/** * $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); }
public function addReport(AnalyzerReport $analyzerReport) { $report = $analyzerReport->getTimestampedReport()->getReport(); if ($this->task->isHaltonerror() && '' === $this->buildErrorMessage && $analyzerReport->getAnalyzer()->getSeverity() === Severity::ERROR) { $this->buildErrorMessage = $report->report(); } if ($this->logfileWriter && $this->logFormat === 'plain') { /** @noinspection PhpParamsInspection */ $this->logfileWriter->write(Plain::formatReportReadable($analyzerReport)); } else { $this->task->log(self::formatReport($analyzerReport), self::severityToPhingLevel($analyzerReport->getAnalyzer()->getSeverity())); } }
/** * 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; }
protected function writeLocalConfigurationArray() { $configuration = new ConfigurationUtility($this->localConfiguration); $phpCode = $configuration->getLocalConfigurationArray(); $this->fileWriter->write($phpCode); $this->fileWriter->close(); }
public function open() { if (!isset($this->document)) { parent::open(); $this->document = new \XLSXWriter(); } }
public function open() { if (!isset($this->document)) { parent::open(); $this->document = new \DOMDocument('1.0', 'utf-8'); } }
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); }
public function open() { if (!isset($this->document)) { parent::open(); $filename = $this->getDDN(); $this->document = fopen($filename, 'w'); } }
/** * * @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(); }
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; }
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); } }
/** * 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; }
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(); }
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(); } }
/** * 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()); } }
/** * 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()) { try { $fr = new FileReader($f); $fr->readInto($value); } catch (Exception $e) { throw $e; } } } // if ends with file.contents if (StringHelper::isBoolean($value)) { $value = StringHelper::booleanValue($value); } $c->assign($property, $value); } // foreach property } // if contextProperties !== null try { //$c->display($this->controlTemplate); $writer->write($c->fetch($this->controlTemplate)); $writer->close(); } catch (IOException $ioe) { $writer->close(); throw new BuildException("Cannot write parsed template."); } $this->cleanup(); }
/** * Transforms the DOM document */ protected function transform(DOMDocument $document) { if (!$this->toDir->exists()) { throw new BuildException("Directory '" . $this->toDir . "' does not exist"); } $xslfile = $this->getStyleSheet(); $xsl = new DOMDocument(); $xsl->load($xslfile->getAbsolutePath()); $proc = new XSLTProcessor(); if (defined('XSL_SECPREF_WRITE_FILE')) { if (version_compare(PHP_VERSION, '5.4', "<")) { ini_set("xsl.security_prefs", XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY); } else { $proc->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY); } } $proc->importStyleSheet($xsl); $proc->setParameter('', 'output.sorttable', $this->useSortTable); if ($this->format == "noframes") { $writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html")); $writer->write($proc->transformToXML($document)); $writer->close(); } else { ExtendedFileStream::registerStream(); $toDir = (string) $this->toDir; // urlencode() the path if we're on Windows if (FileSystem::getFileSystem()->getSeparator() == '\\') { $toDir = urlencode($toDir); } // no output for the framed report // it's all done by extension... $proc->setParameter('', 'output.dir', $toDir); $proc->transformToXML($document); ExtendedFileStream::unregisterStream(); } }
/** * 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, $header = null) { // 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); $fw->open(); if ($header !== null) { $fw->write("# " . $header . Phing::getProperty("line.separator")); } $fw->write($this->toString()); $fw->close(); } catch (IOException $e) { throw new IOException("Error writing property file: " . $e->getMessage()); } }
/** * Execute lint check against PhingFile or a FileSet */ public function main() { if (!isset($this->file) and count($this->filesets) == 0) { throw new BuildException("Missing either a nested fileset or attribute 'file' set"); } if ($this->file instanceof PhingFile) { $this->lint($this->file->getPath()); } else { // process filesets $project = $this->getProject(); foreach ($this->filesets as $fs) { $ds = $fs->getDirectoryScanner($project); $files = $ds->getIncludedFiles(); $dir = $fs->getDir($this->project)->getPath(); foreach ($files as $file) { $this->lint($dir . DIRECTORY_SEPARATOR . $file); } } } // write list of 'bad files' to file (if specified) if ($this->tofile) { $writer = new FileWriter($this->tofile); foreach ($this->badFiles as $file => $messages) { foreach ($messages as $msg) { $writer->write($file . "=" . $msg . PHP_EOL); } } $writer->close(); } // save list of 'bad files' with errors to property errorproperty (if specified) if ($this->errorProperty) { $message = ''; foreach ($this->badFiles as $file => $messages) { foreach ($messages as $msg) { $message .= $file . "=" . $msg . PHP_EOL; } } $this->project->setProperty($this->errorProperty, $message); } if ($this->haltOnFailure && $this->hasErrors) { throw new BuildException('Syntax error(s) in PHP files: ' . implode(', ', $this->badFiles)); } }
/** * Default constructor. * @return void * @throws BuildException */ public function main() { $this->log("Propel - CreoleToXMLSchema starting"); $this->log("Your DB settings are:"); $this->log("driver : " . ($this->dbDriver ? $this->dbDriver : "(default)")); $this->log("URL : " . $this->dbUrl); //(not yet supported) $this->log("schema : " . $this->dbSchema); //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null, // "http://jakarta.apache.org/turbine/dtd/database.dtd"); $this->doc = new DOMDocument('1.0', 'utf-8'); $this->doc->formatOutput = true; // pretty printing $this->doc->appendChild($this->doc->createComment("Autogenerated by CreoleToXMLSchema!")); try { $this->generateXML(); $this->log("Writing XML to file: " . $this->xmlSchema); $outFile = new PhingFile($this->xmlSchema); $out = new FileWriter($outFile); $xmlstr = $this->doc->saveXML(); $out->write($xmlstr); $out->close(); } catch (Exception $e) { $this->log("There was an error building XML from metadata: " . $e->getMessage(), PROJECT_MSG_ERR); } $this->log("Propel - CreoleToXMLSchema finished"); }
/** * Execute lint check against PhingFile or a FileSet */ public function main() { if (!isset($this->file) and count($this->filesets) == 0) { throw new BuildException("Missing either a nested fileset or attribute 'file' set"); } exec($this->executable, $output); if (!preg_match('/JavaScript\\sLint/', implode('', $output))) { throw new BuildException('Javascript Lint not found'); } if ($this->file instanceof PhingFile) { $this->lint($this->file->getPath()); } else { // process filesets $project = $this->getProject(); foreach ($this->filesets as $fs) { $ds = $fs->getDirectoryScanner($project); $files = $ds->getIncludedFiles(); $dir = $fs->getDir($this->project)->getPath(); foreach ($files as $file) { $this->lint($dir . DIRECTORY_SEPARATOR . $file); } } } // write list of 'bad files' to file (if specified) if ($this->tofile) { $writer = new FileWriter($this->tofile); foreach ($this->badFiles as $file => $messages) { foreach ($messages as $msg) { $writer->write($file . "=" . $msg . PHP_EOL); } } $writer->close(); } if ($this->haltOnFailure && $this->hasErrors) { throw new BuildException('Syntax error(s) in JS files:' . implode(', ', array_keys($this->badFiles))); } }
private function appendFile(FileWriter $writer, PhingFile $f) { $in = FileUtils::getChainedReader(new FileReader($f), $this->filterChains, $this->project); while (-1 !== ($buffer = $in->read())) { // -1 indicates EOF $writer->write($buffer); } $this->log("Appending contents of " . $f->getPath() . " to " . $this->to->getPath()); }
/** Append the file(s). */ function main() { if ($this->file === null && empty($this->filesets)) { throw new BuildException("You must specify a file or fileset(s) for the <reflexive> task."); } // compile a list of all files to modify, both file attrib and fileset elements // can be used. $files = array(); if ($this->file !== null) { $files[] = $this->file; } if (!empty($this->filesets)) { $filenames = array(); foreach ($this->filesets as $fs) { try { $ds = $fs->getDirectoryScanner($this->project); $filenames = $ds->getIncludedFiles(); // get included filenames $dir = $fs->getDir($this->project); foreach ($filenames as $fname) { $files[] = new PhingFile($dir, $fname); } } catch (BuildException $be) { $this->log($be->getMessage(), Project::MSG_WARN); } } } $this->log("Applying reflexive processing to " . count($files) . " files."); // These "slots" allow filters to retrieve information about the currently-being-process files $slot = $this->getRegisterSlot("currentFile"); $basenameSlot = $this->getRegisterSlot("currentFile.basename"); foreach ($files as $file) { // set the register slots $slot->setValue($file->getPath()); $basenameSlot->setValue($file->getName()); // 1) read contents of file, pulling through any filters $in = null; try { $contents = ""; $in = FileUtils::getChainedReader(new FileReader($file), $this->filterChains, $this->project); while (-1 !== ($buffer = $in->read())) { $contents .= $buffer; } $in->close(); } catch (Exception $e) { if ($in) { $in->close(); } $this->log("Erorr reading file: " . $e->getMessage(), Project::MSG_WARN); } try { // now create a FileWriter w/ the same file, and write to the file $out = new FileWriter($file); $out->write($contents); $out->close(); $this->log("Applying reflexive processing to " . $file->getPath(), Project::MSG_VERBOSE); } catch (Exception $e) { if ($out) { $out->close(); } $this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN); } } }
/** * Fired when the build finishes, this adds the time taken and any * error stacktrace to the build element and writes the document to disk. * * @param BuildEvent An event with any relevant extra information. * Will not be <code>null</code>. */ function buildFinished(BuildEvent $event) { $this->buildTimer->stop(); $elapsedTime = Phing::currentTimeMillis() - $this->buildTimerStart; $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime)); if ($event->getException() != null) { $this->buildElement->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->toString()); $errText = $this->doc->createCDATASection($event->getException()->getTraceAsString()); $stacktrace = $this->doc->createElement(XmlLogger::STACKTRACE_TAG); $stacktrace->appendChild($errText); $this->buildElement->appendChild($stacktrace); } $outFilename = $event->getProject()->getProperty("XmlLogger.file"); if ($outFilename == "") { $outFilename = "log.xml"; } $writer = new FileWriter($outFilename); $writer->write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); $writer->write($this->doc->saveXML($this->buildElement)); $writer->close(); }
$log->writeLine('Website Configuration Error: ' . $e->getMessage()); $log->close(); } catch (Exception $e) { // ignore } header('HTTP/1.0 500 Error'); die; } // connect to DB try { $db = DbConnection::getInstance(); $db->connect($website->getConfig('db_host'), $website->getConfig('db_user'), $website->getConfig('db_passwort'), $website->getConfig('db_name')); } catch (Exception $e) { // write to log try { $log = new FileWriter('dberrorlog.txt'); $log->writeLine('DB Error: ' . $e->getMessage()); $log->close(); } catch (Exception $e) { // ignore } die('<h1>Sorry, our data base is currently not available</h1><p>We are working on it.</p>'); } // register own session handler $handler = new DbSessionManager($db, $website); session_set_save_handler(array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc')); // the following prevents unexpected effects when using objects as save handlers // see http://php.net/manual/en/function.session-set-save-handler.php register_shutdown_function('session_write_close'); session_start(); // always set time zone in order to prevent PHP warnings
function testExceptionAfterCloseOnWrite() { $fw = FileWriter::newTmpFile(); $this->assertTrue($fw->isOpen(), "Il file temporaneo non risulta aperto!!"); $fw->writeln("Ciao, questo e' un file temporaneo..."); $fw->reset(); $fw->close(); $this->expectException("IllegalStateException"); $line = $fw->writeln("Ciao!!"); }