__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.
Parameters:
__destruct (Destructor) [line 165]
Destructor
Close open files
add [line 437]
Add a new fortune
Parameters:
count [line 271]
Count of fortunes in current active file
create [line 533]
void create(
array
$fortunes, [string
$file = null])
|
|
Create a new fortune file from an array of fortunes
Parameters:
current [line 175]
Return current fortune in iterator
delete [line 464]
Delete an existing fortune
Parameters:
getAll [line 497]
Retrieve all fortunes from the current file
getDirectory [line 426]
Retrieve current directory of fortune files
getFile [line 379]
Retrieve current fortune file name
getHeaderFile [line 401]
Retrieve current header file name
getRandom [line 475]
key [line 193]
Return current iterator key
next [line 211]
Retrieve next element in iterator
offsetExists [line 286]
boolean offsetExists(
int
$offset)
|
|
Does fortune exist at the given offset?
Parameters:
offsetGet [line 310]
string offsetGet(
int
$offset)
|
|
Retrieve fortune by offset
Parameters:
offsetSet [line 330]
void offsetSet(
int
$offset, string
$value)
|
|
Set a fortune at a given offset
Parameters:
offsetUnset [line 345]
void offsetUnset(
int
$offset)
|
|
Delete a fortune at a given offset
Parameters:
rewind [line 234]
Rewind iterator to first element
save [line 519]
setDirectory [line 412]
Set directory from which to randomly select a fortune file
Parameters:
setFile [line 363]
File_Fortune setFile(
string
$file, [string
$headerFile = null])
|
|
Set fortune file
Parameters:
setHeaderFile [line 390]
Set header file name
Parameters:
update [line 452]
void update(
int
$index, string
$fortune)
|
|
Update an existing fortune
Parameters:
valid [line 253]
Current element is valid (iterator)
_close [line 786]
Close fortune file
Closes the fortune file if it's open, and unsets all header-related properties (except $delim); does nothing otherwise.
_computeHeader [line 734]
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.
Parameters:
_getRandomFile [line 590]
Randomly select a fortune file from a registered directory
_initChanges [line 845]
_open [line 554]
_readFromFile [line 821]
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.
Parameters:
_readHeader [line 656]
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.:
$fortune_file = new Fortune('fortunes');
$delim =
$fortune_file->delim;
_save [line 860]
Save changes to disc
Changes to fortunes happen in-memory; this method saves them to disc.
_writeHeader [line 948]