$this->pointer = fopen($this->fqfn, 'w') or debug_report_bug(__METHOD__, __LINE__, 'Cannot write to cache ' . $this->fqfn . ' !');
// Add open PHP tag
- fwrite($this->pointer, "<?php\n");
+ $this->writeLine('<?php');
} else {
// Cannot create file
addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
}
}
+ /**
+ * Writes a line to the pointer and adds a \n (new-line) to the end
+ *
+ * @access private
+ */
+ function writeLine ($line) {
+ // Is the pointer a valid resource?
+ if (is_resource($this->pointer)) {
+ // Write the line
+ fwrite($this->pointer, $line . "\n");
+ } else {
+ // Something bad happened
+ debug_report_bug(__METHOD__, __LINE__, 'Pointer type is ' . gettype($this->pointer) . ', expected is resource.');
+ }
+ }
+
// Reset the read status
function resetCacheReadStatus () {
unset($this->readable[$this->name]);
}
// Write cache line to file
- fwrite($this->pointer, $this->rewriteEntry($k, $v));
+ $this->writeLine($this->rewriteEntry($k, $v));
} // END - foreach
} else {
// Cannot create file
$this->storeExtensionVersion('cache');
// Write footer
- fwrite($this->pointer, "?>\n");
+ $this->writeLine('?>');
// Close file add destroy handler
fclose($this->pointer);
}
// Write line(s)
- fwrite($this->pointer, $LINE);
+ $this->writeLine($LINE);
} // END - foreach
} else {
// Cannot write array!
$this->version[$this->name][$ext_name] = $ext_ver;
// Write cache line to file
- fwrite($this->pointer, $this->rewriteEntry($ext_name, $ext_ver, 'version', true));
+ $this->writeLine($this->rewriteEntry($ext_name, $ext_ver, 'version', true));
} // END - if
//* DEBUG: */ debugOutput(__METHOD__ . '(<font color="#0000aa">' . __LINE__ . '</font>): '.$this->name.' - '.$ext_name.'='.$ext_ver);
} else {
$extender = '[]';
// Add only for single array entry?
- if ($single === true) $extender = '';
+ if ($single === true) {
+ $extender = '';
+ } // END - if
// Init line
$line = '';
// String or non-string? ;-)
if (is_string($value)) {
// String...
- $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = '" . escapeQuotes($value) . "';\n";
+ $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = '" . escapeQuotes($value) . "';";
} elseif (is_null($value)) {
// Null
- $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = null;\n";
+ $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = null;';
} elseif (is_bool($value)) {
// Boolean value
if ($value === true) {
// True
- $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = true;\n";
+ $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = true;';
} else {
// False
- $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . " = false;\n";
+ $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = false;';
}
} elseif (isset($value[0])) {
// These lines needs fixing
debug_report_bug(__METHOD__, __LINE__, 'Invalid entry with [0] found. key=' . $key);
} else {
// Non-string
- $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = ' . $value . ";\n";
+ $line = '$this->' . $prefix . "['" . $this->name . "']['" . $key . "']" . $extender . ' = ' . $value . ';';
}
// Return line
// Debug output
if ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled())) {
- //
- // Debugging stuff...
- //
- $fp = fopen(getCachePath() . 'mysql.log', 'a') or debug_report_bug(__FUNCTION__, __LINE__, 'Cannot write mysql.log!');
+ // Is this the first call?
if (!isset($GLOBALS['sql_first_entry'])) {
// Write first entry
- fwrite($fp, 'Module=' . getModule() . "\n");
+ appendLineToFile(getCachePath() . 'mysql.log', 'Module=' . getModule());
$GLOBALS['sql_first_entry'] = true;
} // END - if
- fwrite($fp, $F . '(LINE=' . $L . '|NUM=' . SQL_NUMROWS($result) . '|AFFECTED=' . SQL_AFFECTEDROWS() . '|QUERYTIME:' . $queryTime . '): ' . str_replace("\r", '', str_replace("\n", ' ', $GLOBALS['last_sql'])) . "\n");
- fclose($fp);
+
+ // Append debug line
+ appendLineToFile(getCachePath() . 'mysql.log', $F . '(LINE=' . $L . '|NUM=' . SQL_NUMROWS($result) . '|AFFECTED=' . SQL_AFFECTEDROWS() . '|QUERYTIME:' . $queryTime . '): ' . str_replace("\r", '', str_replace("\n", ' ', $GLOBALS['last_sql'])));
} // END - if
// Count DB hits