__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 540]
Add a new fortune
Parameters:
count [line 299]
Count of fortunes in current active file, or of all fortunes in all files
create [line 669]
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 577]
Delete an existing fortune
Parameters:
getAll [line 614]
Retrieve all fortunes from the current file or set of files
getDirectory [line 528]
Retrieve current directory of fortune files
getFile [line 430]
Retrieve current fortune file name
getFiles [line 497]
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 452]
Retrieve current header file name
getRandom [line 592]
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 349]
string offsetGet(
int
$offset)
|
|
Retrieve fortune by offset
Parameters:
offsetSet [line 366]
void offsetSet(
int
$offset, string
$value)
|
|
Set a fortune at a given offset
Parameters:
offsetUnset [line 386]
void offsetUnset(
int
$offset)
|
|
Delete a fortune at a given offset
Parameters:
rewind [line 252]
Rewind iterator to first element
save [line 650]
setDirectory [line 511]
Set directory from which to randomly select a fortune file
Parameters:
setFile [line 410]
File_Fortune setFile(
string
$file, [string
$headerFile = null])
|
|
Set fortune file
Setting a file overwrites any directory set as well.
Parameters:
setFiles [line 463]
Set one or more files to search for fortunes
setHeaderFile [line 441]
Set header file name
Parameters:
update [line 560]
void update(
int
$index, string
$fortune)
|
|
Update an existing fortune
Parameters:
valid [line 276]
Current element is valid (iterator)
_close [line 938]
Close fortune file
Closes the fortune file if it's open, and unsets all header-related properties (except $delim); does nothing otherwise.
_computeHeader [line 886]
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 1190]
Retrieve all fortunes from the current active file
_getOne [line 1172]
string _getOne(
int
$offset)
|
|
Retrieve a single fortune by offset
Parameters:
_getRandomFile [line 762]
Randomly select a fortune file from a registered directory
_initChanges [line 997]
_offsetExists [line 1147]
boolean _offsetExists(
int
$offset)
|
|
Retrieve by offset in file
Parameters:
_open [line 694]
_readFromFile [line 973]
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 808]
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 1013]
Save changes to disc
Changes to fortunes happen in-memory; this method saves them to disc.
_traverseDirectory [line 732]
void _traverseDirectory(
)
|
|
Traverse a registered directory to get a list of files
_writeHeader [line 1101]