$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); }
/** * Closes Logger session. * * @throws LoggerException */ public function close() { switch ($this->direction) { case self::TO_OUTPUT_STREAM: OutputStream::close(); return; case self::TO_FILE: // nothing to do return; case self::TO_DB: // nothing to do return; default: throw new LoggerException("Invalid logging output direction type"); } }
/** * Outputs DB query debug information to the stream. * * @param string $query SQL query. * @param string $types SQL types string. * @param array $params List of SQL query parameters. */ public static function showQueryDebugInfo($query = "", $types = "", array $params = array()) { OutputStream::start(); if (!empty($query)) { if (empty($types) && empty($params)) { OutputStream::message(OutputStream::MSG_INFO, "Q: " . $query); } else { if (strlen($types) === count($params)) { $query = preg_replace('/\\s+/', ' ', $query); $preparedQuery = $query; $paramsStr = array(); for ($i = 0; $i < strlen($types); $i++) { $query = preg_replace("/\\?/", DBField::sqlValue($types[$i], $params[$i]), $query, 1); $paramsStr[] = $types[$i] . ": " . DBField::sqlValue($types[$i], $params[$i]); } OutputStream::message(OutputStream::MSG_INFO, "Q: " . $query); OutputStream::message(OutputStream::MSG_INFO, "P: " . $preparedQuery); OutputStream::message(OutputStream::MSG_INFO, "A: [" . implode(", ", $paramsStr) . "]"); } else { OutputStream::message(OutputStream::MSG_ERROR, "Number of types is not equal parameters number."); OutputStream::message(OutputStream::MSG_INFO, "T: " . $types); OutputStream::message(OutputStream::MSG_INFO, "A: [" . implode(", ", $params) . "]"); } } } else { OutputStream::message(OutputStream::MSG_WARNING, "DB query is empty."); } OutputStream::close(); }