File_Fortune
[ class tree: File_Fortune ] [ index: File_Fortune ] [ all elements ]

Class: File_Fortune

Source Location: /File_Fortune-0.9.2/File/Fortune.php

Class Overview


File_Fortune


Author(s):

Version:

  • @release-version@

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 35]
File_Fortune

File_Fortune: Interface to fortune cookie databases

The <em>fortune</em> program is a small but important part of *nix culture, and this package aims to provide support for its "fortune cookie" databases to PHP programmers.

  • Tutorial: File_Fortune.cls
  • Version: @release-version@
  • Uses: Iterator
  • Uses: Countable
  • Uses: ArrayAccess


[ Top ]


Class Variables

$delim =  '%'

[line 43]

Character that delimits fortunes (defaults to '%')
  • Access: public

Type:   string


[ Top ]

$maxLength =

[line 49]

Length of longest string in the fortune file
  • Access: public

Type:   int


[ Top ]

$minLength =

[line 55]

Length of shortest string in the fortune file
  • Access: public

Type:   int


[ Top ]

$numstr =

[line 128]

Number of strings (fortunes) in the file
  • Access: public

Type:   int


[ Top ]

$offsets =

[line 134]

Array of file offsets (fortune indices)
  • Access: protected

Type:   array


[ Top ]

$version =

[line 61]

Version number for fortune file
  • Access: public

Type:   int


[ Top ]

$_changed =  false

[line 67]

Flag - has an operation changed the file?
  • Access: protected

Type:   boolean


[ Top ]

$_curOffset =  1

[line 73]

Current offset (used by iterator)
  • Access: protected

Type:   int


[ Top ]

$_directory =

[line 79]

Directory containing fortune files
  • Access: protected

Type:   string


[ Top ]

$_file =

[line 85]

Fortune file filehandle
  • Access: protected

Type:   resource


[ Top ]

$_filename =

[line 91]

Name of fortune file to use
  • Access: protected

Type:   string


[ Top ]

$_files =

[line 97]

Array of fortune files found in $_directory
  • Access: protected

Type:   array


[ Top ]

$_flags =

[line 103]

Bit field for flags
  • Access: protected

Type:   array


[ Top ]

$_fortunes =

[line 109]

Array of fortunes; unset by default.
  • Access: protected

Type:   array


[ Top ]

$_headerFile =

[line 115]

Name of fortune header file (.dat file)
  • Access: protected

Type:   string


[ Top ]

$_noHeader =  false

[line 122]

Flag indicating whether or not a header file is present. Defaults to false.
  • Access: protected

Type:   bool


[ Top ]



Method Detail

__construct (Constructor)   [line 147]

void __construct( [string $file = null], [string $headerFile = null])

Constructor

Optionally pass a filename or directory name to set the fortune file or directory, and, if passing a fortune file name, optionally pass the name of the header file.

  • Access: public

Parameters:

string   $file   — 
string   $headerFile   — 

[ Top ]

__destruct (Destructor)   [line 165]

void __destruct( )

Destructor

Close open files

  • Access: public

[ Top ]

add   [line 479]

File_Fortune add( string $fortune)

Add a new fortune
  • Access: public

Parameters:

string   $fortune   — 

[ Top ]

count   [line 271]

int count( )

Count of fortunes in current active file
  • Access: public

[ Top ]

create   [line 575]

void create( array $fortunes, [string $file = null])

Create a new fortune file from an array of fortunes
  • Access: public

Parameters:

array   $fortunes   — 
string   $file   — 

[ Top ]

current   [line 175]

string current( )

Return current fortune in iterator
  • Access: public

[ Top ]

delete   [line 506]

void delete( int $index)

Delete an existing fortune
  • Access: public

Parameters:

int   $index   — 

[ Top ]

getAll   [line 539]

array getAll( )

Retrieve all fortunes from the current file
  • Access: public

[ Top ]

getDirectory   [line 468]

string getDirectory( )

Retrieve current directory of fortune files
  • Access: public

[ Top ]

getFile   [line 379]

string getFile( )

Retrieve current fortune file name
  • Access: public

[ Top ]

getFiles   [line 440]

array getFiles( )

Return list of fortune files in use

Returns a list of fortune files in use, either as registered via setFiles() or as determined by traversing the directory set via setDirectory().

  • Access: public

[ Top ]

getHeaderFile   [line 401]

string getHeaderFile( )

Retrieve current header file name
  • Access: public

[ Top ]

getRandom   [line 517]

string getRandom( )

Retrieve random fortune
  • Access: public

[ Top ]

key   [line 193]

int key( )

Return current iterator key
  • Access: public

[ Top ]

next   [line 211]

string|false next( )

Retrieve next element in iterator
  • Access: public

[ Top ]

offsetExists   [line 286]

boolean offsetExists( int $offset)

Does fortune exist at the given offset?
  • Access: public

Parameters:

int   $offset   — 

[ Top ]

offsetGet   [line 310]

string offsetGet( int $offset)

Retrieve fortune by offset
  • Access: public

Parameters:

int   $offset   — 

[ Top ]

offsetSet   [line 330]

void offsetSet( int $offset, string $value)

Set a fortune at a given offset
  • Access: public

Parameters:

int   $offset   — 
string   $value   — 

[ Top ]

offsetUnset   [line 345]

void offsetUnset( int $offset)

Delete a fortune at a given offset
  • Access: public

Parameters:

int   $offset   — 

[ Top ]

rewind   [line 234]

bool rewind( )

Rewind iterator to first element
  • Access: public

[ Top ]

save   [line 561]

void save( )

Save changes
  • Access: public

[ Top ]

setDirectory   [line 454]

File_Fortune setDirectory( string $directory)

Set directory from which to randomly select a fortune file
  • Access: public

Parameters:

string   $directory   — 

[ Top ]

setFile   [line 363]

File_Fortune setFile( string $file, [string $headerFile = null])

Set fortune file
  • Access: public

Parameters:

string   $file   — 
string   $headerFile   — 

[ Top ]

setFiles   [line 411]

File_Fortune setFiles( )

Set one or more files to search for fortunes
  • Access: public

[ Top ]

setHeaderFile   [line 390]

File_Fortune setHeaderFile( string $headerFile)

Set header file name
  • Access: public

Parameters:

string   $headerFile   — 

[ Top ]

update   [line 494]

void update( int $index, string $fortune)

Update an existing fortune
  • Access: public

Parameters:

int   $index   — 
string   $fortune   — 

[ Top ]

valid   [line 253]

bool valid( )

Current element is valid (iterator)
  • Access: public

[ Top ]

_close   [line 839]

void _close( )

Close fortune file

Closes the fortune file if it's open, and unsets all header-related properties (except $delim); does nothing otherwise.

  • Access: protected

[ Top ]

_computeHeader   [line 787]

void _computeHeader( [string $delim = '%'])

Compute fortune file header information

Reads the contents of the fortune file and computes the header information that would normally be found in a header (.dat) file and read by _readHeader(). This is useful if you maintain a file of fortunes by hand and do not have the corresponding data file.

An optional delimiter argument may be passed to this function; if present, that delimiter will be used to separate entries in the fortune file. If not provided, a percent sign ("%") will be used (this is the standard fortune file delimiter).

Additionally, the $noHeader property will be set to true.

NOTE: It is most efficient to use fortune files that have header files. In order to get offsets and fortunes, this method actually must read the entire fortune file, and stores all fortunes in the $_fortunes array.

  • Throws: File_Fortune_Exception
  • Access: protected

Parameters:

string   $delim   —  Defaults to '%'

[ Top ]

_getRandomFile   [line 663]

void _getRandomFile( )

Randomly select a fortune file from a registered directory
  • Access: protected

[ Top ]

_initChanges   [line 898]

void _initChanges( )

Initialize changes
  • Access: protected

[ Top ]

_open   [line 596]

void _open( )

Open a fortune file
  • Access: protected

[ Top ]

_readFromFile   [line 874]

string _readFromFile( int $offset)

Read a fortune from the file

Reads a fortune directly from the file. If an error occurs, an exception is thrown. Otherwise, on sucess, the fortune is returned.

  • Throws: File_Fortune_Exception
  • Access: protected

Parameters:

int   $offset   — 

[ Top ]

_readHeader   [line 709]

void _readHeader( )

Read a fortune database header file

Reads the header file associated with this fortune database. The name of the header file is determined by the constructor: either it is based on the name of the data file, or supplied by the caller.

If the header file does not exist, this function calls _computeHeader() automatically, which has the same effect as reading the header from a file.

The header contains the following values, which are stored as attributes of the File_Fortune object:

  • $version; version number
  • $numstr; number of strings (fortunes) in the file
  • $maxLength; length of longest string in the file
  • $minLength; length of shortest string in the file
  • $flags; bit field for flags (see strfile(1) man page)
  • $delim; character that delimits fortunes

$numstr is available via the count() function (count($fortunes)); if you're interested in the others, you'll have to go grubbing through the File_Fortune object, e.g.:

  1.  $fortune_file = new Fortune('fortunes');
  2.  $delim        $fortune_file->delim;
  3.  $maxLength    $fortune_file->maxLength;

  • Throws: File_Fortune_Exception
  • Access: protected

[ Top ]

_save   [line 913]

void _save( )

Save changes to disc

Changes to fortunes happen in-memory; this method saves them to disc.

  • Access: protected

[ Top ]

_traverseDirectory   [line 633]

void _traverseDirectory( )

Traverse a registered directory to get a list of files
  • Access: protected

[ Top ]

_writeHeader   [line 1001]

void _writeHeader( )

Write the header file for a fortune file

Writes a fortune header file to $headerFilename, using $version, $numstr, $maxLength, $minLength, $flags, $delim, and $offsets.

If an error occurs, an exception is thrown.

  • Throws: File_Fortune_Exception
  • Access: protected

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:06:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.