__construct (Constructor) [line 147]
void __construct(
[string|array
$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 167]
Destructor
Close open files
add [line 561]
Add a new fortune
Parameters:
count [line 299]
Count of fortunes in current active file, or of all fortunes in all files
create [line 690]
void create(
array
$fortunes, [string
$file = null])
|
|
Create a new fortune file from an array of fortunes
Parameters:
current [line 178]
Return current fortune in iterator
delete [line 598]
Delete an existing fortune
Parameters:
getAll [line 635]
Retrieve all fortunes from the current file or set of files
getDirectory [line 549]
Retrieve current directory of fortune files
getFile [line 451]
Retrieve current fortune file name
getFiles [line 518]
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().
getHeaderFile [line 473]
Retrieve current header file name
getRandom [line 613]
key [line 201]
Return current iterator key
next [line 224]
Retrieve next element in iterator
offsetExists [line 333]
boolean offsetExists(
int
$offset)
|
|
Does fortune exist at the given offset?
Parameters:
offsetGet [line 362]
string offsetGet(
int
$offset)
|
|
Retrieve fortune by offset
Parameters:
offsetSet [line 387]
void offsetSet(
int
$offset, string
$value)
|
|
Set a fortune at a given offset
Parameters:
offsetUnset [line 407]
void offsetUnset(
int
$offset)
|
|
Delete a fortune at a given offset
Parameters:
rewind [line 252]
Rewind iterator to first element
save [line 671]
setDirectory [line 532]
Set directory from which to randomly select a fortune file
Parameters:
setFile [line 431]
File_Fortune setFile(
string
$file, [string
$headerFile = null])
|
|
Set fortune file
Setting a file overwrites any directory set as well.
Parameters:
setFiles [line 484]
Set one or more files to search for fortunes
setHeaderFile [line 462]
Set header file name
Parameters:
update [line 581]
void update(
int
$index, string
$fortune)
|
|
Update an existing fortune
Parameters:
valid [line 276]
Current element is valid (iterator)
_close [line 959]
Close fortune file
Closes the fortune file if it's open, and unsets all header-related properties (except $delim); does nothing otherwise.
_computeHeader [line 907]
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:
_getAll [line 1167]
Retrieve all fortunes from the current active file
_getRandomFile [line 783]
Randomly select a fortune file from a registered directory
_initChanges [line 1018]
_open [line 715]
_readFromFile [line 994]
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 829]
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 1034]
Save changes to disc
Changes to fortunes happen in-memory; this method saves them to disc.
_traverseDirectory [line 753]
void _traverseDirectory(
)
|
|
Traverse a registered directory to get a list of files
_writeHeader [line 1122]