本文整理汇总了PHP中FileWriter::close方法的典型用法代码示例。如果您正苦于以下问题:PHP FileWriter::close方法的具体用法?PHP FileWriter::close怎么用?PHP FileWriter::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileWriter
的用法示例。
在下文中一共展示了FileWriter::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeLocalConfigurationArray
protected function writeLocalConfigurationArray()
{
$configuration = new ConfigurationUtility($this->localConfiguration);
$phpCode = $configuration->getLocalConfigurationArray();
$this->fileWriter->write($phpCode);
$this->fileWriter->close();
}
示例2: 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);
}
示例3: 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();
}
示例4: 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);
}
}
示例5: main
/**
* 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));
}
}
示例6: main
/**
* 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: main
/**
* 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: copyFrom
/**
* @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: 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());
}
}
示例10: main
/**
* 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: write
/**
* 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: _writeFile
/**
* 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: elseif
<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 . ' » ' . $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>» <a href=\'?site=' . $site . '\'>' . $i18n->getMessage('back_label') . '</a></p>';
}
}
示例14: doReportTempDir
/**
* 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: logAdminAction
/**
* 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();
}