本文整理汇总了PHP中SqlFormatter::pre_attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlFormatter::pre_attributes方法的具体用法?PHP SqlFormatter::pre_attributes怎么用?PHP SqlFormatter::pre_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlFormatter
的用法示例。
在下文中一共展示了SqlFormatter::pre_attributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public static function init(&$report)
{
$environments = PhpReports::$config['environments'];
if (!isset($environments[$report->options['Environment']][$report->options['Database']])) {
throw new Exception("No " . $report->options['Database'] . " database defined for environment '" . $report->options['Environment'] . "'");
}
//make sure the syntax highlighting is using the proper class
SqlFormatter::$pre_attributes = "class='prettyprint linenums lang-sql'";
$object = spyc_load($report->raw_query);
$report->raw_query = array();
//if there are any included reports, add the report sql to the top
if (isset($report->options['Includes'])) {
$included_sql = '';
foreach ($report->options['Includes'] as &$included_report) {
$included_sql .= trim($included_report->raw_query) . "\n";
}
if (strlen($included_sql) > 0) {
$report->raw_query[] = $included_sql;
}
}
$report->raw_query[] = $object;
//set a formatted query here for debugging. It will be overwritten below after macros are substituted.
//We can not set the query here - it's not a query just yet...
//$report->options['Query_Formatted'] = SqlFormatter::format($report->raw_query);
}
示例2: init
public static function init(&$report)
{
$environments = PhpReports::$config['environments'];
if (!isset($environments[$report->options['Environment']][$report->options['Database']])) {
throw new Exception("No " . $report->options['Database'] . " info defined for environment '" . $report->options['Environment'] . "'");
}
//make sure the syntax highlighting is using the proper class
SqlFormatter::$pre_attributes = "class='prettyprint linenums lang-sql'";
$mysql = $environments[$report->options['Environment']][$report->options['Database']];
//default host macro to mysql's host if it isn't defined elsewhere
if (!isset($report->macros['host'])) {
$report->macros['host'] = $mysql['host'];
}
//replace legacy shorthand macro format
foreach ($report->macros as $key => $value) {
if (isset($report->options['Variables'][$key])) {
$params = $report->options['Variables'][$key];
} else {
$params = array();
}
//macros shortcuts for arrays
if (isset($params['multiple']) && $params['multiple']) {
//allow {macro} instead of {% for item in macro %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}
//this is shorthand for comma separated list
$report->raw_query = preg_replace('/([^\\{])\\{' . $key . '\\}([^\\}])/', '$1{% for item in ' . $key . ' %}{% if not loop.first %},{% endif %}\'{{ item }}\'{% endfor %}$2', $report->raw_query);
//allow {(macro)} instead of {% for item in macro %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}
//this is shorthand for quoted, comma separated list
$report->raw_query = preg_replace('/([^\\{])\\{\\(' . $key . '\\)\\}([^\\}])/', '$1{% for item in ' . $key . ' %}{% if not loop.first %},{% endif %}(\'{{ item }}\'){% endfor %}$2', $report->raw_query);
} else {
//allow {macro} instead of {{macro}} for legacy support
$report->raw_query = preg_replace('/([^\\{])(\\{' . $key . '+\\})([^\\}])/', '$1{$2}$3', $report->raw_query);
}
}
//if there are any included reports, add the report sql to the top
if (isset($report->options['Includes'])) {
$included_sql = '';
foreach ($report->options['Includes'] as &$included_report) {
$included_sql .= trim($included_report->raw_query) . "\n";
}
$report->raw_query = $included_sql . $report->raw_query;
}
//set a formatted query here for debugging. It will be overwritten below after macros are substituted.
$report->options['Query_Formatted'] = SqlFormatter::format($report->raw_query);
}
示例3: formatQuery
/**
* Formats and/or highlights the given SQL statement.
*
* @param string $sql
* @param bool $highlightOnly If true the query is not formatted, just highlighted
*
* @return string
*/
public function formatQuery($sql, $highlightOnly = false)
{
\SqlFormatter::$pre_attributes = 'class="highlight highlight-sql"';
\SqlFormatter::$quote_attributes = 'class="string"';
\SqlFormatter::$backtick_quote_attributes = 'class="string"';
\SqlFormatter::$reserved_attributes = 'class="keyword"';
\SqlFormatter::$boundary_attributes = 'class="symbol"';
\SqlFormatter::$number_attributes = 'class="number"';
\SqlFormatter::$word_attributes = 'class="word"';
\SqlFormatter::$error_attributes = 'class="error"';
\SqlFormatter::$comment_attributes = 'class="comment"';
\SqlFormatter::$variable_attributes = 'class="variable"';
if ($highlightOnly) {
$html = \SqlFormatter::highlight($sql);
$html = preg_replace('/<pre class=".*">([^"]*+)<\\/pre>/Us', '\\1', $html);
} else {
$html = \SqlFormatter::format($sql);
$html = preg_replace('/<pre class="(.*)">([^"]*+)<\\/pre>/Us', '<div class="\\1"><pre>\\2</pre></div>', $html);
}
return $html;
}
示例4: highlightSQL
/**
* Highlight SQL syntax.
*
* @param string $sql
* @return string
*/
public function highlightSQL($sql)
{
\SqlFormatter::$pre_attributes = '';
return trim(substr(\SqlFormatter::highlight($sql), 6, -6));
}
示例5: getPanel
/**
* Renders HTML code for custom panel.
* @return string
*/
public function getPanel()
{
$queries = $this->queries;
$html = '<h1>' . self::$title . '</h1>';
$html .= '<div class="tracy-inner tracy-InfoPanel"><table width="300">';
\SqlFormatter::$pre_attributes = 'style="color: black;"';
foreach ($queries as $query) {
$html .= '<tr><td>' . \SqlFormatter::highlight($query) . '</td></tr>';
}
$html .= '</table></div>';
return $html;
}