public static get_output ( mixed $var, string $title = '', boolean $escape = true, string $space = '', boolean $short = false, integer $depth ) : string | ||
$var | mixed | Variable to show. |
$title | string | (optional) Variable title. |
$escape | boolean | (optional) Whether to character escape the textual output. |
$space | string | (internal) Indentation spacing. |
$short | boolean | (internal) Short or normal annotation. |
$depth | integer | (internal) The depth of the current recursion. |
return | string |
public static function get_output($var, $title = '', $escape = true, $space = '', $short = false, $depth = 0)
{
$output = '';
if ('' === $space) {
$output .= '<div class="db-pretty-var">';
}
if (is_string($title) && '' !== $title) {
$output .= '<h4 style="clear: both;">' . (true === $escape ? esc_html($title) : $title) . "</h4>\n";
}
if (is_array($var)) {
if (!empty($var)) {
$output .= 'Array: <br />' . $space . '(<br />';
if (is_int(self::$limit_recursion) && $depth > self::$limit_recursion) {
$output .= '... ( ' . sprintf(__('output limited at recursion depth %d', 'db-pretty-output'), self::$limit_recursion) . ')<br />';
} else {
if (true !== $short) {
$spacing = $space . ' ';
} else {
$spacing = $space . ' ';
}
foreach ($var as $key => $value) {
$output .= $spacing . '[' . (true === $escape ? esc_html($key) : $key);
if (true !== $short) {
$output .= ' ';
switch (true) {
case is_string($key):
$output .= '<span style="color: #336600;;"><b><i>(string)</i></b></span>';
break;
case is_int($key):
$output .= '<span style="color: #FF0000;"><b><i>(int)</i></b></span>';
break;
case is_float($key):
$output .= '<span style="color: #990033;"><b><i>(float)</i></b></span>';
break;
default:
$output .= '(' . __('unknown', 'db-pretty-output') . ')';
break;
}
}
$output .= '] => ';
$output .= self::get_output($value, '', $escape, $spacing, $short, ++$depth);
}
unset($key, $value);
}
$output .= $space . ')<br />';
} else {
$output .= 'array()<br />';
}
} else {
if (is_string($var)) {
$output .= self::get_pretty_string($var, $short, $escape);
} else {
if (is_bool($var)) {
$output .= self::get_pretty_bool($var, $short);
} else {
if (is_int($var)) {
$output .= self::get_pretty_int($var, $short);
} else {
if (is_float($var)) {
$output .= self::get_pretty_float($var, $short);
} else {
if (is_null($var)) {
$output .= self::get_pretty_null($var, $short);
} else {
if (is_resource($var)) {
$output .= self::get_pretty_resource($var, $short);
} else {
if (is_object($var)) {
$output .= 'Object: <br />' . $space . '(<br />';
if (is_int(self::$limit_recursion) && $depth > self::$limit_recursion) {
$output .= '... ( ' . sprintf(__('output limited at recursion depth %d', 'db-pretty-output'), self::$limit_recursion) . ')<br />';
} else {
if (true !== $short) {
$spacing = $space . ' ';
} else {
$spacing = $space . ' ';
}
$output .= self::get_object_info($var, $escape, $spacing, $short, ++$depth);
}
$output .= $space . ')<br /><br />';
} else {
$output .= esc_html__('I haven\'t got a clue what this is: ', 'db-pretty-output') . gettype($var) . '<br />';
}
}
}
}
}
}
}
}
if ('' === $space) {
$output .= '</div>';
}
return $output;
}
/** * Create a property table for standard/custom properties. * * @since 1.2 * * @param array $properties Array of post type properties. * @param array $names Array of post type names. * @param string $table_name Translated name for this table. * @param bool $double Whether or not to repeat the row labels at the end of the table. */ protected function render_property_table($properties, $names, $table_name, $double) { /* Create header row. */ $header_row = ' <tr> <th>' . esc_html__('Property', self::DBPT_NAME) . '</th>'; foreach ($names as $name) { $header_row .= ' <th>' . esc_html($name) . '</th>'; } unset($name); if ($double === true) { $header_row .= ' <th class="' . self::DBPT_NAME . '-table-end">' . esc_html__('Property', self::DBPT_NAME) . '</th>'; } $header_row .= ' </tr>'; echo ' <h3>', esc_html($table_name), '</h3> <table class="debug-bar-table ', self::DBPT_NAME, '"> <thead> ', $header_row, ' </thead> <tfoot> ', $header_row, ' </tfoot> <tbody>'; unset($header_row); /* Sort. */ uksort($properties, 'strnatcasecmp'); /* Output. */ foreach ($properties as $key => $value) { echo ' <tr> <th>', esc_html($key), '</th>'; foreach ($names as $name) { echo ' <td>'; if (isset($value[$name])) { if (defined('Debug_Bar_Pretty_Output::VERSION')) { echo Debug_Bar_Pretty_Output::get_output($value[$name], '', true, '', true); // WPCS: XSS ok. } else { // An old version of the pretty output class was loaded. Debug_Bar_Pretty_Output::output($value[$name], '', true, '', true); } } else { echo ' '; } echo ' </td>'; } unset($name); if ($double === true) { echo ' <th class="', self::DBPT_NAME, '-table-end">', esc_html($key), '</th>'; // WPCS: XSS ok. } echo ' </tr>'; } unset($key, $value); echo ' </tbody> </table> '; }