Class outputfile

Description

The outputfile class manages files for outputting content. This includes both appending to an existing file, and creating new files. The method used in both cases is to write to a temporary file, and then rename/move it onto the final file path when closefile() is called.

Located in /file-defs.php (line 440)


	
			
Direct descendents
Class Description
 class quickfile This is a derived class from outputfile and is a quick way of creating a file with content in a single hit. You can check the $created property afterwards to determine success/failure.
Variable Summary
 mixed $datafname
 mixed $dir
 mixed $filetype
 mixed $fp
 mixed $name
 mixed $opened
 mixed $savehow
 mixed $tempfname
 mixed $template_fp
Method Summary
 boolean outputfile (string $name, [string $dir = ""], [string $savehow = "overwrite"])
 boolean closefile ([integer $mode = SAVE_FILE])
 boolean flushbuffer ()
 void replace (string $tag, string $newstuff)
 void template (string $path)
 void type (string $type)
 bool write (string $s)
 bool writeln (string $s)
Variables
mixed $datafname = "" (line 447)

The full path to the file

mixed $dir = "" (line 445)

The directory prefix (if any) of the file

mixed $filetype = "text" (line 449)

Type of file 'text' or 'templated'

mixed $fp (line 467)

File pointer

mixed $name = "" (line 443)

The file name

mixed $opened = false (line 451)

True if file was sucessfully opened

mixed $savehow = "overwrite" (line 453)

How to save: default "overwrite", or "append" to append.

mixed $tempfname = "" (line 464)

Full pathname of destination (temporary) file

mixed $template_contents = "" (line 461)

Content of template file when read in

mixed $template_fname = "" (line 458)

Full pathname of template file

mixed $template_fp (line 470)

File pointer

Methods
Constructor outputfile (line 483)

Constructor

Note that we open a temporary file, write to this file, and only move it to the destination when closed. This means it is less prone to interferring with external processes which might be accessing it when in the process of being built.

  • return: True if file was opened, else false
boolean outputfile (string $name, [string $dir = ""], [string $savehow = "overwrite"])
  • string $name: The name of the file
  • string $dir: The directory the file is in
  • string $savehow: "overwrite" (default), or "append"
closefile (line 585)

Close the file. We move the temporary file that has been built to

the actual file path contained in 'datafname'. If this is called with no argument, then the default mode SAVE_MODE is assumed and the file is saved. However if the argument is set to the constant ABANDON_FILE then nothing will be saved/created.

  • return: True if file was saved and closed successfully.
boolean closefile ([integer $mode = SAVE_FILE])
  • integer $mode: How to save: SAVE_FILE or ABANDON_FILE
flushbuffer (line 568)

Flush any buffered content to the stream.

  • return: True if stream was flushed, else false
boolean flushbuffer ()
replace (line 558)

Replace a pattern in the current $this->content with replacement string. This allows us to work on a template, replacing bits of it that represent our dynamic content.

void replace (string $tag, string $newstuff)
  • string $tag: The pattern in the template to replace
  • string $newstuff: The replacement content
template (line 540)

This defines a template for the file content and flags the file as being of "templated" type. The template is expected to be at the $path specified. The template is opened and the entire file contents are put into $this->content.

void template (string $path)
  • string $path: The path to the template file
type (line 529)

Set the file type. Possible types include 'text' (default), 'html', and 'templated'.

void type (string $type)
  • string $type: The file type
write (line 639)

Write to file Write the given string to the output file.

  • return: True if write was successful
bool write (string $s)
  • string $s: The string to write to the file
writeln (line 650)

Write line to file Write the given string to the output file as a line.

  • return: True if writeln was successful
bool writeln (string $s)
  • string $s: The string to write as a line to the file

Documentation generated by phpDocumentor 1.3.0RC3