/** * Main logging method, performes log writing. * * @param int $type Log message type. * @param string $message Message text. * @param string $format Time label format. * @param int $time Timestamp. * * @throws LoggerException */ public function log($type, $message, $format = "\\[Y-m-d H:i:s\\]", $time = null) { $msgType = null; switch ($type) { case self::LOG_INFO: $msgType = OutputStream::MSG_INFO; break; case self::LOG_DEBUG: $msgType = OutputStream::MSG_DEBUG; break; case self::LOG_SUCCESS: $msgType = OutputStream::MSG_SUCCESS; break; case self::LOG_WARNING: $msgType = OutputStream::MSG_WARNING; break; case self::LOG_ERROR: $msgType = OutputStream::MSG_ERROR; break; default: throw new LoggerException("Invalid message type"); } switch ($this->direction) { case self::TO_OUTPUT_STREAM: OutputStream::msg($msgType, $message, $format, $time); return; case self::TO_FILE: $message = "({$type}) " . $message; if (strpos($message, "{{time}}") === false) { $message = "{{time}} " . $message; } if (is_null($time)) { $time = time(); } $message = str_replace("{{time}}", date($format, $time), $message); file_put_contents($this->fileName, "{$message}\n", FILE_APPEND); return; case self::TO_DB: $this->dbObject->log($type, $message, $time = null); return; default: throw new LoggerException("Invalid logging output direction type"); } }
$idFieldName = 'id'; $fieldsListStr = ""; $fieldsList = DBCore::getTableFieldsList($tableName); if (!empty($fieldsList)) { foreach ($fieldsList as $field => $attributes) { if ($attributes['key'] === 'PRI') { $idFieldName = $field; } $fieldsListStr .= " " . DBCore::getPrintableFieldString($field, $attributes); } $fieldsListStr = substr($fieldsListStr, 0, strlen($fieldsListStr) - 1); $className = getClassName($tableName); $content = str_replace(array('{{CLASS_NAME}}', '{{TABLE_NAME}}', '{{PRIMARY_KEY}}', '{{FIELDS_LIST}}', '{{YEAR}}', '{{AUTHOR}}', '{{EMAIL}}'), array($className, $tableName, $idFieldName, $fieldsListStr, date("Y"), AUTHOR, EMAIL), $tpl); file_put_contents(RESULTS_PATH . $className . ".php", $content); OutputStream::msg(OutputStream::MSG_SUCCESS, "Class '" . RESULTS_PATH . $className . ".php' generated."); } else { OutputStream::msg(OutputStream::MSG_ERROR, "Can't read structure for table '" . $tableName . "'."); } } $stmt->close(); } else { OutputStream::msg(OutputStream::MSG_ERROR, "Can't read tables list."); } OutputStream::close(); function getClassName($tableName) { $underlinesReplaced = preg_replace_callback("/_([a-zA-Z]{1})/", function ($matches) { return strtoupper($matches[1]); }, $tableName); return ucfirst($underlinesReplaced); }