本文整理匯總了PHP中JFile::append方法的典型用法代碼示例。如果您正苦於以下問題:PHP JFile::append方法的具體用法?PHP JFile::append怎麽用?PHP JFile::append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JFile
的用法示例。
在下文中一共展示了JFile::append方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addEntry
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return boolean True on success.
*
* @since 11.1
* @throws RuntimeException
*/
public function addEntry(JLogEntry $entry)
{
// Initialise the file if not already done.
$this->initFile();
// Set some default field values if not already set.
if (!isset($entry->clientIP)) {
// Check for proxies as well.
if (isset($_SERVER['REMOTE_ADDR'])) {
$entry->clientIP = $_SERVER['REMOTE_ADDR'];
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$entry->clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$entry->clientIP = $_SERVER['HTTP_CLIENT_IP'];
}
}
// If the time field is missing or the date field isn't only the date we need to rework it.
if (strlen($entry->date) != 10 || !isset($entry->time)) {
// Get the date and time strings in GMT.
$entry->datetime = $entry->date->toISO8601();
$entry->time = $entry->date->format('H:i:s', false);
$entry->date = $entry->date->format('Y-m-d', false);
}
// Get a list of all the entry keys and make sure they are upper case.
$tmp = array_change_key_case(get_object_vars($entry), CASE_UPPER);
// Decode the entry priority into an English string.
$tmp['PRIORITY'] = $this->priorities[$entry->priority];
// Fill in field data for the line.
$line = $this->format;
foreach ($this->fields as $field) {
$line = str_replace('{' . $field . '}', isset($tmp[$field]) ? $tmp[$field] : '-', $line);
}
// Write the new entry to the file.
$line .= "\n";
if (!JFile::append($this->path, $line)) {
throw new RuntimeException('Cannot write to log file.');
}
}