protected function writeLocalConfigurationArray()
 {
     $configuration = new ConfigurationUtility($this->localConfiguration);
     $phpCode = $configuration->getLocalConfigurationArray();
     $this->fileWriter->write($phpCode);
     $this->fileWriter->close();
 }
Пример #2
0
 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);
 }
 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();
 }
 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);
     }
 }
Пример #5
0
 /**
  * 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");
 }
Пример #7
0
 /**
  * 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)));
     }
 }
Пример #8
0
 /**
  * @param IFile $file The source file to copy from.
  * @return bool TRUE if the file has been successfully copied from $file, FALSE if an error occured
  * Note: An exception is raised if an important error is detected (the copy of a single file failed),
  *       but during a folder copy, a failure during the copy of a single "sub-file" is ignored and no
  *       exception is raised.
  *       Nevertheless, you can check if the copy was a full success by testing the returned value.
  * @throws EyeIOException
  * @throws EyeFileNotFoundException
  */
 protected function copyFrom(IFile $file, $overwrite = true)
 {
     if ($this->isDirectory() && (!$file->isDirectory() || $this->getName() != $file->getName())) {
         if ($this->getName() != '/' || $file->getName() != '/') {
             return $this->getChildFile($file->getName())->copyFrom($file, $overwrite);
         }
     }
     if ($this->exists() && !$overwrite) {
         throw new EyeIOException($this->path . '" exists and can\'t be overwritten.');
     }
     //FILE or LINK
     if ($file->isFile() || $file->isLink()) {
         $srcPath = AdvancedPathLib::getPhpLocalHackPath($file->getPath());
         $destPath = AdvancedPathLib::getPhpLocalHackPath($this->path);
         // First, let's try with the function provided by PHP, but only working with
         // a very restricted range of filesystems
         if (copy($srcPath, $destPath)) {
             return true;
         }
         if (!$this->exists() && !$this->createNewFile(true)) {
             throw new EyeIOException('Unable to create destination file ' . $this->path . '.');
         }
         try {
             $fileWriter = new FileWriter($this->getOutputStream());
             $fileReader = new FileReader($file->getInputStream());
             $buffer = null;
             while ($fileReader->read($buffer) !== 0) {
                 $fileWriter->write($buffer);
             }
             $fileReader->close();
             $fileWriter->close();
             return true;
         } catch (Exception $e) {
             if (is_object($fileReader)) {
                 $fileReader->close();
             }
             if (is_object($fileWriter)) {
                 $fileWriter->close();
             }
             throw new EyeIOException('Unable to transfer files contents ' . $file->getPath() . ' => ' . $this->path . '.', 0, $e);
         }
     } elseif ($file->isDirectory()) {
         if ($this->isDirectory() || $this->mkdirs()) {
             $success = true;
             foreach ($file->listFiles() as $subFile) {
                 try {
                     if (!$subFile->copyTo($this)) {
                         $success = false;
                     }
                 } catch (Exception $e) {
                     $success = false;
                 }
             }
             return $success;
         } else {
             throw new EyeIOException('Unable to create destination directory ' . $this->path . '.');
         }
     } else {
         throw new EyeFileNotFoundException($file->getPath() . ' does not exist.');
     }
 }
Пример #9
0
 /**
  * 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());
     }
 }
 /**
  * Default constructor.
  * @return     void
  * @throws     BuildException
  */
 public function main()
 {
     include_once 'creole/Creole.php';
     if (!class_exists('Creole')) {
         throw new BuildException(get_class($this) . " task depends on Creole classes being on include_path. (i.e. include of 'creole/Creole.php' failed.)", $this->getLocation());
     }
     $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");
 }
Пример #11
0
 /**
  * Internal function to write data store to file
  *
  * @throws BuildException
  * @return none
  */
 private function write()
 {
     if (!$this->file->canWrite()) {
         throw new BuildException("Can't write data store to '" . $this->file->getPath() . "'");
     } else {
         $serializedData = serialize($this->data);
         $writer = new FileWriter($this->file);
         $writer->write($serializedData);
         $writer->close();
     }
 }
Пример #12
0
 /**
  * Writing a file.
  * 
  * @param  PhingFile $file    The file to write
  * @param  mixed     $content The file's content
  * @return void
  * @throws BuildException
  * @access protected
  **/
 protected function _writeFile(PhingFile $file, $content)
 {
     if ($this->_preserveLastModified) {
         $lastModified = $file->lastModified();
     }
     $output = new FileWriter($file);
     $output->write($content);
     $output->close();
     if ($this->_preserveLastModified) {
         $file->setLastModified($lastModified);
     }
 }
Пример #13
0
		<input type='submit' class='btn btn-primary' accesskey='s' title='Alt + s' value='<?php 
    echo $i18n->getMessage('button_save');
    ?>
'> 
		<input type='reset' class='btn' value='<?php 
    echo $i18n->getMessage('button_reset');
    ?>
'>
	</div>    
  </form>

  
  <?php 
} elseif ($show == 'save') {
    if (!isset($_POST['content']) || !$_POST['content']) {
        $err[] = $i18n->getMessage('imprint_validationerror_content');
    }
    if ($admin['r_demo']) {
        $err[] = $i18n->getMessage('validationerror_no_changes_as_demo');
    }
    if (isset($err)) {
        include 'validationerror.inc.php';
    } else {
        echo '<h1>' . $mainTitle . ' &raquo; ' . $i18n->getMessage('subpage_save_title') . '</h1>';
        $fw = new FileWriter(IMPRINT_FILE);
        $fw->writeLine(stripslashes($_POST['content']));
        $fw->close();
        echo createSuccessMessage($i18n->getMessage('alert_save_success'), '');
        echo '<p>&raquo; <a href=\'?site=' . $site . '\'>' . $i18n->getMessage('back_label') . '</a></p>';
    }
}
Пример #14
0
 /**
  * try and create a temp file in our temp dir; this
  * checks that it has space and access.
  * We also do some clock reporting.
  *
  * @param PrintStream $out
  */
 private static function doReportTempDir(PrintStream $out)
 {
     $tempdir = PhingFile::getTempDir();
     if ($tempdir == null) {
         $out->println("Warning: php.tmpdir is undefined");
         return;
     }
     $out->println("Temp dir is " . $tempdir);
     $tempDirectory = new PhingFile($tempdir);
     if (!$tempDirectory->exists()) {
         $out->println("Warning, php.tmpdir directory does not exist: " . $tempdir);
         return;
     }
     $now = time();
     $tempFile = PhingFile::createTempFile('diag', 'txt', $tempDirectory);
     $fileWriter = new FileWriter($tempFile);
     $fileWriter->write('some test text');
     $fileWriter->close();
     $filetime = $tempFile->lastModified();
     $tempFile->delete();
     $out->println("Temp dir is writeable");
     $drift = $filetime - $now;
     $out->println("Temp dir alignment with system clock is " . $drift . " s");
     if (abs($drift) > 10) {
         $out->println("Warning: big clock drift -maybe a network filesystem");
     }
 }
Пример #15
0
/**
 * Writes a log statement into the entity log file.
 * 
 * @param WebSoccer $websoccer application context.
 * @param string $type edit|delete
 * @param string $username name of admin who executed an action.
 * @param string $entity name of affacted entity.
 * @param string $entityValue string value which identifies the entity item.
 */
function logAdminAction(WebSoccer $websoccer, $type, $username, $entity, $entityValue)
{
    $userIp = getenv('REMOTE_ADDR');
    $message = $websoccer->getFormattedDatetime($websoccer->getNowAsTimestamp()) . ';' . $username . ';' . $userIp . ';' . $type . ';' . $entity . ';' . $entityValue;
    $file = BASE_FOLDER . '/generated/entitylog.php';
    $fw = new FileWriter($file, FALSE);
    $fw->writeLine($message);
    $fw->close();
}
Пример #16
0
 /**
  * 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();
     }
 }
Пример #18
0
 /**
  * @throws     BuildException
  */
 public function main()
 {
     if (!$this->getDatabaseName()) {
         throw new BuildException("The databaseName attribute (defined in propel.project property) is required for schema reverse engineering", $this->getLocation());
     }
     //(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 " . get_class($this) . " class."));
     try {
         $database = $this->buildModel();
         if ($this->validatorBits !== self::VALIDATORS_NONE) {
             $this->addValidators($database);
         }
         $database->appendXml($this->doc);
         $this->log("Writing XML to file: " . $this->xmlSchema->getPath());
         $out = new FileWriter($this->xmlSchema);
         $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);
         return false;
     }
     $this->log("Schema reverse engineering finished");
 }
Пример #19
0
 /** 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);
         }
     }
 }
Пример #20
0
 /**
  * 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();
 }
Пример #21
0
    } 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
try {
    date_default_timezone_set($website->getConfig('time_zone'));
Пример #22
0
 /**
  * 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());
     }
 }